From 05727dd9f4f0ac1dd2de4089b58cbe85b0d79a6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Mon, 2 Mar 2026 14:44:17 +0000 Subject: [PATCH] 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) --- Build/build-functions.psm1 | 13 --- Build/build-pack-nano-nugets.psm1 | 4 +- Build/init.ps1 | 95 ------------------- .../NanoFrameworkGen/NuspecGenerator.cs | 4 +- .../NanoFrameworkGen/ProjectGenerator.cs | 2 - .../NanoFrameworkGen/PropertyGenerator.cs | 4 - CodeGen/Generators/NanoFrameworkGenerator.cs | 14 +-- CodeGen/Program.cs | 6 +- azure-pipelines-pr.yml | 2 + azure-pipelines.yml | 2 + 10 files changed, 19 insertions(+), 127 deletions(-) diff --git a/Build/build-functions.psm1 b/Build/build-functions.psm1 index 66bd3e1c4d..b41a94aca9 100644 --- a/Build/build-functions.psm1 +++ b/Build/build-functions.psm1 @@ -51,19 +51,6 @@ function Start-Build { function Start-BuildNanoFramework { write-host -foreground blue "Start-BuildNanoFramework (MSBuild)...`n---" - # Check prerequisites - if (-not $msbuildx64 -or -not (Test-Path $msbuildx64)) { - write-host -foreground red "ERROR: Cannot build .NET nanoFramework - MSBuild not found." - write-host -foreground yellow "Install Visual Studio with .NET desktop development workload to build NanoFramework projects." - exit 1 - } - - if (-not (Test-Path $nuget)) { - write-host -foreground red "ERROR: NuGet.exe not found at $nuget" - write-host -foreground yellow "Run init.ps1 to download required tools." - exit 1 - } - write-host -foreground green "Building .NET nanoFramework projects..." $fileLoggerArg = "/logger:FileLogger,Microsoft.Build;logfile=$logsDir\UnitsNet.NanoFramework.msbuild.log" diff --git a/Build/build-pack-nano-nugets.psm1 b/Build/build-pack-nano-nugets.psm1 index b2ed5c3e79..161a130fa0 100644 --- a/Build/build-pack-nano-nugets.psm1 +++ b/Build/build-pack-nano-nugets.psm1 @@ -1,13 +1,11 @@ $root = (Resolve-Path "$PSScriptRoot\..").Path $nugetOutDir = "$root\Artifacts\NuGet" -$toolsDir = "$root\.tools" -$nuget = "$toolsDir\NuGet.exe" $nugetsToProcess = (Get-ChildItem -Path "$root\UnitsNet.NanoFramework\GeneratedCode\" -Filter *.nuspec -r | % { echo $_.FullName }); function Invoke-BuildNanoNugets { Foreach ($nuspecFile in $nugetsToProcess) { - & $nuget pack "$nuspecFile" -Verbosity detailed -OutputDirectory "$nugetOutDir" + & nuget pack "$nuspecFile" -Verbosity detailed -OutputDirectory "$nugetOutDir" } } diff --git a/Build/init.ps1 b/Build/init.ps1 index e96fffffc9..b730dadad5 100644 --- a/Build/init.ps1 +++ b/Build/init.ps1 @@ -17,106 +17,11 @@ if (-not (Test-Path "$root/.tools/reportgenerator.exe")) { Write-Host -Foreground Green "✅ Installed dotnet-reportgenerator-globaltool" } -# NuGet.exe for non-SDK style projects, like UnitsNet.nanoFramework. -if (-not (Test-Path "$nugetPath")) { - Write-Host -Foreground Blue "Downloading NuGet.exe..." - Invoke-WebRequest -Uri https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile $nugetPath - Write-Host -Foreground Green "✅ Downloaded NuGet.exe: $nugetPath" -} - -################################################### -## TODO: OK to remove after moving to AZDO pipeline -$VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe" - -# Check if Visual Studio is installed -if (Test-Path $VsWherePath) { - $VsPath = $(&$VsWherePath -latest -property installationPath 2>$null) - if ($VsPath) { - $msbuildPath = Join-Path -Path $VsPath -ChildPath "\MSBuild" - Write-Host -Foreground Green "Visual Studio found at: $VsPath" - } else { - Write-Host -Foreground Yellow "Visual Studio not found via vswhere, NanoFramework builds will be skipped" - $VsPath = $null - $msbuildPath = $null - } -} else { - Write-Host -Foreground Yellow "Visual Studio not installed - NanoFramework builds will be skipped" - $VsPath = $null - $msbuildPath = $null -} - # Install dotnet CLI tools declared in /.config/dotnet-tools.json pushd $root dotnet tool restore popd -# Install .NET nanoFramework build components -if ($msbuildPath -and !(Test-Path "$msbuildPath/nanoFramework")) { - Write-Host "Installing .NET nanoFramework VS extension..." - - [System.Net.WebClient]$webClient = New-Object System.Net.WebClient - $webClient.Headers.Add("User-Agent", "request") - $webClient.Headers.Add("Accept", "application/vnd.github.v3+json") - - $releaseList = $webClient.DownloadString('https://api.github.com/repos/nanoframework/nf-Visual-Studio-extension/releases?per_page=100') - - if($releaseList -match '\"(?v2022\.\d+\.\d+\.\d+)\"') - { - $vs2022Tag = $Matches.VS2022_version - } - - if($releaseList -match '\"(?v2019\.\d+\.\d+\.\d+)\"') - { - $vs2019Tag = $Matches.VS2019_version - } - - # Find which VS version is installed - $VsWherePath = "${env:PROGRAMFILES(X86)}\Microsoft Visual Studio\Installer\vswhere.exe" - - Write-Output "VsWherePath is: $VsWherePath" - - $VsInstance = $(&$VSWherePath -latest -property displayName 2>$null) - - Write-Output "Latest VS is: $VsInstance" - - # Get extension details according to VS version, starting from VS2022 down to VS2019 - # TODO check if the extension for VS2022 is compatible it VS2026 - if($vsInstance.Contains('2026') -or $vsInstance.Contains('2022')) - { - $extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2022Tag/nanoFramework.Tools.VS2022.Extension.vsix" - $vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2022.Extension.zip" - $extensionVersion = $vs2022Tag - } - elseif($vsInstance.Contains('2019')) - { - $extensionUrl = "https://github.com/nanoframework/nf-Visual-Studio-extension/releases/download/$vs2019Tag/nanoFramework.Tools.VS2019.Extension.vsix" - $vsixPath = Join-Path $tempDir "nanoFramework.Tools.VS2019.Extension.zip" - $extensionVersion = $vs2019Tag - } - - Write-Output "Downloading visx..." - - # download VS extension - Write-Host "Download VSIX file from $extensionUrl to $vsixPath" - $webClient.DownloadFile($extensionUrl, $vsixPath) - - $outputPath = "$tempDir\nf-extension" - - $vsixPath = Join-Path -Path $tempDir -ChildPath "nf-extension.zip" - $webClient.DownloadFile($extensionUrl, $vsixPath) - - Write-Host "Extract VSIX file to $outputPath" - Expand-Archive -LiteralPath $vsixPath -DestinationPath $outputPath -Force | Write-Host - - $copyFrom = "$outputPath\`$MSBuild\nanoFramework" - - Write-Host "Copy from $copyFrom to $msbuildPath" - Copy-Item -Path "$copyFrom" -Destination $msbuildPath -Recurse - - Write-Host "Installed VS extension $extensionVersion" -} -################################################### - # Cleanup [system.io.Directory]::Delete($tempDir, $true) | out-null diff --git a/CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs b/CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs index c5fbe836a0..204bf1d7c7 100644 --- a/CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs +++ b/CodeGen/Generators/NanoFrameworkGen/NuspecGenerator.cs @@ -1,4 +1,4 @@ -using System; +using System; using CodeGen.JsonTypes; namespace CodeGen.Generators.NanoFrameworkGen @@ -52,7 +52,7 @@ public string Generate() - + "); diff --git a/CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs b/CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs index f07787513d..a53536cc1e 100644 --- a/CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs +++ b/CodeGen/Generators/NanoFrameworkGen/ProjectGenerator.cs @@ -46,7 +46,6 @@ public string Generate() ..\packages\nanoFramework.CoreLibrary.{_versions.MscorlibNugetVersion}\lib\mscorlib.dll True - True "); if (NanoFrameworkGenerator.ProjectsRequiringMath.Contains(_quantity.Name)) @@ -55,7 +54,6 @@ public string Generate() ..\packages\nanoFramework.System.Math.{_versions.MathNugetVersion}\lib\System.Math.dll True - True "); } diff --git a/CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs b/CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs index 6973936633..cf6fd65ff3 100644 --- a/CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs +++ b/CodeGen/Generators/NanoFrameworkGen/PropertyGenerator.cs @@ -45,10 +45,6 @@ public string Generate() [assembly: AssemblyVersion(""{_version}"")] [assembly: AssemblyFileVersion(""{_version}"")] -////////////////////////////////////////////////// -// This assembly doens't require native support // -[assembly: AssemblyNativeVersion(""0.0.0.0"")] -////////////////////////////////////////////////// "); return Writer.ToString(); } diff --git a/CodeGen/Generators/NanoFrameworkGenerator.cs b/CodeGen/Generators/NanoFrameworkGenerator.cs index 19d8cab43c..daa16e5550 100644 --- a/CodeGen/Generators/NanoFrameworkGenerator.cs +++ b/CodeGen/Generators/NanoFrameworkGenerator.cs @@ -108,9 +108,11 @@ public static void Generate(string rootDir, Quantity[] quantities, QuantityNameT /// /// The root directory /// The quantities to update nuspec files + /// Use nanoFramework preview builds? Defaults to false. public static bool UpdateNanoFrameworkDependencies( string rootDir, - Quantity[] quantities) + Quantity[] quantities, + bool usePreview) { // working path var path = Path.Combine(rootDir, "UnitsNet.NanoFramework\\GeneratedCode"); @@ -175,7 +177,7 @@ public static bool UpdateNanoFrameworkDependencies( StartInfo = new ProcessStartInfo { FileName = Path.Combine(rootDir, ".tools/NuGet.exe"), - Arguments = $"update {path}\\UnitsNet.nanoFramework.sln -PreRelease", + Arguments = $"update {path}\\UnitsNet.nanoFramework.sln {(usePreview ? "-PreRelease" : "")}", UseShellExecute = false, CreateNoWindow = true, RedirectStandardError = true @@ -266,9 +268,9 @@ private static NanoFrameworkVersions ParseCurrentNanoFrameworkVersions(string ro new Regex(@"[\d\.]+),.*"">", RegexOptions.IgnoreCase), "mscorlib assembly version"); - // ..\packages\nanoFramework.CoreLibrary.1.10.5-preview.18\lib\mscorlib.dll + // ..\packages\nanoFramework.CoreLibrary.1.10.5-preview.18\lib\netnano1.0\mscorlib.dll var mscorlibNuGetVersion = ParseVersion(projectFileContent, - new Regex(@".*[\\\/]nanoFramework\.CoreLibrary\.(?.*?)[\\\/]lib[\\\/]mscorlib.dll<", RegexOptions.IgnoreCase), + new Regex(@".*[\\\/]nanoFramework\.CoreLibrary\.(?.*?)[\\\/]lib[\\\/](?:netnano[\d\.]+[\\\/])?mscorlib\.dll<", RegexOptions.IgnoreCase), "nanoFramework.CoreLibrary nuget version"); // @@ -276,9 +278,9 @@ private static NanoFrameworkVersions ParseCurrentNanoFrameworkVersions(string ro new Regex(@"[\d\.]+),.*"">", RegexOptions.IgnoreCase), "System.Math assembly version"); - // ..\packages\nanoFramework.System.Math.1.4.1-preview.7\lib\System.Math.dll + // ..\packages\nanoFramework.System.Math.1.4.1-preview.7\lib\netnano1.0\System.Math.dll var mathNuGetVersion = ParseVersion(projectFileContent, - new Regex(@".*[\\\/]nanoFramework\.System\.Math\.(?.*?)[\\\/]lib[\\\/]System.Math.dll<", RegexOptions.IgnoreCase), + new Regex(@".*[\\\/]nanoFramework\.System\.Math\.(?.*?)[\\\/]lib[\\\/](?:netnano[\d\.]+[\\\/])?System\.Math\.dll<", RegexOptions.IgnoreCase), "nanoFramework.System.Math nuget version"); return new NanoFrameworkVersions(mscorlibVersion, mscorlibNuGetVersion, mathVersion, mathNuGetVersion); diff --git a/CodeGen/Program.cs b/CodeGen/Program.cs index 31038895de..7a3194b7a5 100644 --- a/CodeGen/Program.cs +++ b/CodeGen/Program.cs @@ -45,7 +45,8 @@ public class Program /// The repository root directory, defaults to searching parent directories for UnitsNet.sln. /// Skip generate nanoFramework Units? Defaults to false /// Update nanoFramework nuget dependencies? Defaults to false. - public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = null, bool skipNanoFramework = false, bool updateNanoFrameworkDependencies = false) + /// Use nanoFramework preview builds? Defaults to false. + public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = null, bool skipNanoFramework = false, bool updateNanoFrameworkDependencies = false, bool useNanoPreview = false) { Log.Logger = new LoggerConfiguration() .WriteTo @@ -77,7 +78,8 @@ public static int Main(bool verbose = false, DirectoryInfo? repositoryRoot = nul { if (!NanoFrameworkGenerator.UpdateNanoFrameworkDependencies( rootDir, - quantities)) + quantities, + useNanoPreview)) { return 1; } diff --git a/azure-pipelines-pr.yml b/azure-pipelines-pr.yml index e3c0ad742c..6cca4346d3 100644 --- a/azure-pipelines-pr.yml +++ b/azure-pipelines-pr.yml @@ -58,6 +58,8 @@ stages: - task: InstallNanoMSBuildComponents@1 displayName: Install .NET nanoFramework MSBuild components + inputs: + usePreview: $(UseNanoPreview) - task: PowerShell@2 displayName: 'Build, test, pack' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 567befc561..f29142a63c 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -51,6 +51,8 @@ stages: - task: InstallNanoMSBuildComponents@1 displayName: Install .NET nanoFramework MSBuild components + inputs: + usePreview: $(UseNanoPreview) - task: PowerShell@2 displayName: 'Build, test, pack'