Skip to content

Commit 774af9b

Browse files
committed
Updates on nanoFramework build components
- Add optional parameter to choose preview builds (and nuget packages). - Update nuspec (and code generator) to use offical nano1.0 Target Framework Moniker. - Remove unnused declaration properties generator. - Remove unnecessary property in reference project entry. - Remove all checks and installer for nanoFramework VS extension, as all that is handled in AZDO step. - Remove pre-check of nuget and msbuild as builds are now running in ADZO which include these in the VM image. - Add input to install nanoFramework build components to allow specifying preview build. (settable from pipeline var UseNanoPreview)
1 parent b837f76 commit 774af9b

File tree

9 files changed

+18
-124
lines changed

9 files changed

+18
-124
lines changed

Build/build-functions.psm1

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,6 @@ function Start-Build {
5151
function Start-BuildNanoFramework {
5252
write-host -foreground blue "Start-BuildNanoFramework (MSBuild)...`n---"
5353

54-
# Check prerequisites
55-
if (-not $msbuildx64 -or -not (Test-Path $msbuildx64)) {
56-
write-host -foreground red "ERROR: Cannot build .NET nanoFramework - MSBuild not found."
57-
write-host -foreground yellow "Install Visual Studio with .NET desktop development workload to build NanoFramework projects."
58-
exit 1
59-
}
60-
61-
if (-not (Test-Path $nuget)) {
62-
write-host -foreground red "ERROR: NuGet.exe not found at $nuget"
63-
write-host -foreground yellow "Run init.ps1 to download required tools."
64-
exit 1
65-
}
66-
6754
write-host -foreground green "Building .NET nanoFramework projects..."
6855
$fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log"
6956

Build/init.ps1

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -17,106 +17,11 @@ if (-not (Test-Path "$root/.tools/reportgenerator.exe")) {
1717
Write-Host -Foreground Green "✅ Installed dotnet-reportgenerator-globaltool"
1818
}
1919

20-
# NuGet.exe for non-SDK style projects, like UnitsNet.nanoFramework.
21-
if (-not (Test-Path "$nugetPath")) {
22-
Write-Host -Foreground Blue "Downloading NuGet.exe..."
23-
Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $nugetPath
24-
Write-Host -Foreground Green "✅ Downloaded NuGet.exe: $nugetPath"
25-
}
26-
27-
###################################################
28-
## TODO: OK to remove after moving to AZDO pipeline
29-
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"
30-
31-
# Check if Visual Studio is installed
32-
if (Test-Path $VsWherePath) {
33-
$VsPath = $(&$VsWherePath -latest -property installationPath 2>$null)
34-
if ($VsPath) {
35-
$msbuildPath = Join-Path -Path $VsPath -ChildPath "\MSBuild"
36-
Write-Host -Foreground Green "Visual Studio found at: $VsPath"
37-
} else {
38-
Write-Host -Foreground Yellow "Visual Studio not found via vswhere, NanoFramework builds will be skipped"
39-
$VsPath = $null
40-
$msbuildPath = $null
41-
}
42-
} else {
43-
Write-Host -Foreground Yellow "Visual Studio not installed - NanoFramework builds will be skipped"
44-
$VsPath = $null
45-
$msbuildPath = $null
46-
}
47-
4820
# Install dotnet CLI tools declared in /.config/dotnet-tools.json
4921
pushd $root
5022
dotnet tool restore
5123
popd
5224

53-
# Install .NET nanoFramework build components
54-
if ($msbuildPath -and !(Test-Path "$msbuildPath/nanoFramework")) {
55-
Write-Host "Installing .NET nanoFramework VS extension..."
56-
57-
[System.Net.WebClient]$webClient = New-Object System.Net.WebClient
58-
$webClient.Headers.Add("User-Agent", "request")
59-
$webClient.Headers.Add("Accept", "application/vnd.github.v3+json")
60-
61-
$releaseList = $webClient.DownloadString('https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100')
62-
63-
if($releaseList -match '\"(?<VS2022_version>v2022\.\d+\.\d+\.\d+)\"')
64-
{
65-
$vs2022Tag = $Matches.VS2022_version
66-
}
67-
68-
if($releaseList -match '\"(?<VS2019_version>v2019\.\d+\.\d+\.\d+)\"')
69-
{
70-
$vs2019Tag = $Matches.VS2019_version
71-
}
72-
73-
# Find which VS version is installed
74-
$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe"
75-
76-
Write-Output "VsWherePath is: $VsWherePath"
77-
78-
$VsInstance = $(&$VSWherePath -latest -property displayName 2>$null)
79-
80-
Write-Output "Latest VS is: $VsInstance"
81-
82-
# Get extension details according to VS version, starting from VS2022 down to VS2019
83-
# TODO check if the extension for VS2022 is compatible it VS2026
84-
if($vsInstance.Contains('2026') -or $vsInstance.Contains('2022'))
85-
{
86-
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2022Tag/nanoFramework.Tools.VS2022.Extension.vsix"
87-
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip"
88-
$extensionVersion = $vs2022Tag
89-
}
90-
elseif($vsInstance.Contains('2019'))
91-
{
92-
$extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2019Tag/nanoFramework.Tools.VS2019.Extension.vsix"
93-
$vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip"
94-
$extensionVersion = $vs2019Tag
95-
}
96-
97-
Write-Output "Downloading visx..."
98-
99-
# download VS extension
100-
Write-Host "Download VSIX file from $extensionUrl to $vsixPath"
101-
$webClient.DownloadFile($extensionUrl, $vsixPath)
102-
103-
$outputPath = "$tempDir\nf-extension"
104-
105-
$vsixPath = Join-Path -Path $tempDir -ChildPath "nf-extension.zip"
106-
$webClient.DownloadFile($extensionUrl, $vsixPath)
107-
108-
Write-Host "Extract VSIX file to $outputPath"
109-
Expand-Archive -LiteralPath $vsixPath -DestinationPath $outputPath -Force | Write-Host
110-
111-
$copyFrom = "$outputPath\`$MSBuild\nanoFramework"
112-
113-
Write-Host "Copy from $copyFrom to $msbuildPath"
114-
Copy-Item -Path "$copyFrom" -Destination $msbuildPath -Recurse
115-
116-
Write-Host "Installed VS extension $extensionVersion"
117-
}
118-
###################################################
119-
12025
# Cleanup
12126
[system.io.Directory]::Delete($tempDir, $true) | out-null
12227

CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using CodeGen.JsonTypes;
33

44
namespace CodeGen.Generators.NanoFrameworkGen
@@ -52,7 +52,7 @@ public string Generate()
5252
</dependencies>
5353
</metadata>
5454
<files>
55-
<file src=""..\..\..\Artifacts\UnitsNet.NanoFramework\{_quantity.Name}\UnitsNet.*"" target=""lib"" />
55+
<file src=""..\..\..\Artifacts\UnitsNet.NanoFramework\{_quantity.Name}\UnitsNet.*"" target=""lib\netnano1.0"" />
5656
</files>
5757
</package>");
5858

CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public string Generate()
4646
<Reference Include=""mscorlib, Version={_versions.MscorlibVersion}, Culture=neutral, PublicKeyToken=c07d481e9758c731"">
4747
<HintPath>..\packages\nanoFramework.CoreLibrary.{_versions.MscorlibNugetVersion}\lib\mscorlib.dll</HintPath>
4848
<Private>True</Private>
49-
<SpecificVersion>True</SpecificVersion>
5049
</Reference>");
5150

5251
if (NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name))
@@ -55,7 +54,6 @@ public string Generate()
5554
<Reference Include=""System.Math, Version={_versions.MathVersion}, Culture=neutral, PublicKeyToken=c07d481e9758c731"">
5655
<HintPath>..\packages\nanoFramework.System.Math.{_versions.MathNugetVersion}\lib\System.Math.dll</HintPath>
5756
<Private>True</Private>
58-
<SpecificVersion>True</SpecificVersion>
5957
</Reference>");
6058
}
6159

CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@ public string Generate()
4545
[assembly: AssemblyVersion(""{_version}"")]
4646
[assembly: AssemblyFileVersion(""{_version}"")]
4747
48-
//////////////////////////////////////////////////
49-
// This assembly doens't require native support //
50-
[assembly: AssemblyNativeVersion(""0.0.0.0"")]
51-
//////////////////////////////////////////////////
5248
");
5349
return Writer.ToString();
5450
}

CodeGen/Generators/NanoFrameworkGenerator.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ public static void Generate(string rootDir, Quantity[] quantities, QuantityNameT
108108
/// </summary>
109109
/// <param name="rootDir">The root directory</param>
110110
/// <param name="quantities">The quantities to update nuspec files</param>
111+
/// <param name="usePreview">Use nanoFramework preview builds? Defaults to false.</param>
111112
public static bool UpdateNanoFrameworkDependencies(
112113
string rootDir,
113-
Quantity[] quantities)
114+
Quantity[] quantities,
115+
bool usePreview)
114116
{
115117
// working path
116118
var path = Path.Combine(rootDir, "UnitsNet.NanoFramework\\GeneratedCode");
@@ -175,7 +177,7 @@ public static bool UpdateNanoFrameworkDependencies(
175177
StartInfo = new ProcessStartInfo
176178
{
177179
FileName = Path.Combine(rootDir, ".tools/NuGet.exe"),
178-
Arguments = $"update {path}\\UnitsNet.nanoFramework.sln -PreRelease",
180+
Arguments = $"update {path}\\UnitsNet.nanoFramework.sln {(usePreview ? "-PreRelease" : "")}",
179181
UseShellExecute = false,
180182
CreateNoWindow = true,
181183
RedirectStandardError = true
@@ -266,19 +268,19 @@ private static NanoFrameworkVersions ParseCurrentNanoFrameworkVersions(string ro
266268
new Regex(@"<Reference Include=""mscorlib,\s*Version=(?<version>[\d\.]+),.*"">", RegexOptions.IgnoreCase),
267269
"mscorlib assembly version");
268270

269-
// <HintPath>..\packages\nanoFramework.CoreLibrary.1.10.5-preview.18\lib\mscorlib.dll</HintPath>
271+
// <HintPath>..\packages\nanoFramework.CoreLibrary.1.10.5-preview.18\lib\netnano1.0\mscorlib.dll</HintPath>
270272
var mscorlibNuGetVersion = ParseVersion(projectFileContent,
271-
new Regex(@"<HintPath>.*[\\\/]nanoFramework\.CoreLibrary\.(?<version>.*?)[\\\/]lib[\\\/]mscorlib.dll<", RegexOptions.IgnoreCase),
273+
new Regex(@"<HintPath>.*[\\\/]nanoFramework\.CoreLibrary\.(?<version>.*?)[\\\/]lib[\\\/](?:netnano[\d\.]+[\\\/])?mscorlib\.dll<", RegexOptions.IgnoreCase),
272274
"nanoFramework.CoreLibrary nuget version");
273275

274276
// <Reference Include="System.Math, Version=1.4.1.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
275277
var mathVersion = ParseVersion(projectFileContent,
276278
new Regex(@"<Reference Include=""System.Math,\s*Version=(?<version>[\d\.]+),.*"">", RegexOptions.IgnoreCase),
277279
"System.Math assembly version");
278280

279-
// <HintPath>..\packages\nanoFramework.System.Math.1.4.1-preview.7\lib\System.Math.dll</HintPath>
281+
// <HintPath>..\packages\nanoFramework.System.Math.1.4.1-preview.7\lib\netnano1.0\System.Math.dll</HintPath>
280282
var mathNuGetVersion = ParseVersion(projectFileContent,
281-
new Regex(@"<HintPath>.*[\\\/]nanoFramework\.System\.Math\.(?<version>.*?)[\\\/]lib[\\\/]System.Math.dll<", RegexOptions.IgnoreCase),
283+
new Regex(@"<HintPath>.*[\\\/]nanoFramework\.System\.Math\.(?<version>.*?)[\\\/]lib[\\\/](?:netnano[\d\.]+[\\\/])?System\.Math\.dll<", RegexOptions.IgnoreCase),
282284
"nanoFramework.System.Math nuget version");
283285

284286
return new NanoFrameworkVersions(mscorlibVersion, mscorlibNuGetVersion, mathVersion, mathNuGetVersion);

CodeGen/Program.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ public class Program
4545
/// <param name="repositoryRoot">The repository root directory, defaults to searching parent directories for UnitsNet.sln.</param>
4646
/// <param name="skipNanoFramework">Skip generate nanoFramework Units? Defaults to false</param>
4747
/// <param name="updateNanoFrameworkDependencies">Update nanoFramework nuget dependencies? Defaults to false.</param>
48-
public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = null, bool skipNanoFramework = false, bool updateNanoFrameworkDependencies = false)
48+
/// <param name="useNanoPreview">Use nanoFramework preview builds? Defaults to false.</param>
49+
public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = null, bool skipNanoFramework = false, bool updateNanoFrameworkDependencies = false, bool useNanoPreview = false)
4950
{
5051
Log.Logger = new LoggerConfiguration()
5152
.WriteTo
@@ -77,7 +78,8 @@ public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = nul
7778
{
7879
if (!NanoFrameworkGenerator.UpdateNanoFrameworkDependencies(
7980
rootDir,
80-
quantities))
81+
quantities,
82+
useNanoPreview))
8183
{
8284
return 1;
8385
}

azure-pipelines-pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ stages:
5858

5959
- task: InstallNanoMSBuildComponents@1
6060
displayName: Install .NET nanoFramework MSBuild components
61+
inputs:
62+
usePreview: $(UseNanoPreview)
6163

6264
- task: PowerShell@2
6365
displayName: 'Build, test, pack'

azure-pipelines.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ stages:
5151

5252
- task: InstallNanoMSBuildComponents@1
5353
displayName: Install .NET nanoFramework MSBuild components
54+
inputs:
55+
usePreview: $(UseNanoPreview)
5456

5557
- task: PowerShell@2
5658
displayName: 'Build, test, pack'

0 commit comments

Comments
 (0)