From 3908a78286454058c6642b1873e08f5f82afb19e Mon Sep 17 00:00:00 2001 From: Klaus Loffelmann Date: Fri, 3 Jul 2026 09:30:42 -0700 Subject: [PATCH] Refactor build.cmd for ARM64 and add build.cmd.ps1 * Refactored build.cmd to delegate to a new PowerShell script (build.cmd.ps1) for improved argument parsing and platform detection. * Added support for building on Windows ARM64 via the -platform arm64 option, which sets TargetArchitecture and disables NativeToolsOnMachine. * Updated documentation to reflect the new ARM64 build instructions. --- build.cmd | 2 +- docs/building.md | 1 + eng/build.cmd.ps1 | 65 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 eng/build.cmd.ps1 diff --git a/build.cmd b/build.cmd index 9852a061a26..c25a3fbebe1 100755 --- a/build.cmd +++ b/build.cmd @@ -1,3 +1,3 @@ @echo off -powershell -ExecutionPolicy ByPass -NoProfile -command "& """%~dp0eng\common\Build.ps1""" -NativeToolsOnMachine -restore -build -bl %*" +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0eng\build.cmd.ps1" %* exit /b %ErrorLevel% diff --git a/docs/building.md b/docs/building.md index 25f26541301..da5a785bb75 100644 --- a/docs/building.md +++ b/docs/building.md @@ -10,6 +10,7 @@ Follow the prerequisites listed at [Developer Guide](developer-guide.md). * Run `.\build.cmd` from the repository root. This builds the `Winforms.sln` using the default config (Debug|Any CPU). * To specify a build configuration, add `-configuration` followed by the config such as `.\build -configuration Release`. +* To build on Windows ARM64, use `.\build -platform arm64`. This maps the solution platform to `TargetArchitecture=arm64` without promoting local Visual Studio native tool paths. Note that this does **not** build using your machine-wide installed version of the dotnet sdk. It builds using the repo-local .NET SDK specified in the global.json in the repository root. diff --git a/eng/build.cmd.ps1 b/eng/build.cmd.ps1 new file mode 100644 index 00000000000..50ab390e38b --- /dev/null +++ b/eng/build.cmd.ps1 @@ -0,0 +1,65 @@ +[CmdletBinding(PositionalBinding = $false)] +param( + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $BuildArgs +) + +$forwardArgs = [System.Collections.Generic.List[string]]::new() +$useNativeTools = $true +$isArm64Platform = $false +$hasTargetArchitecture = $false + +for ($i = 0; $i -lt $BuildArgs.Length; $i++) { + $arg = $BuildArgs[$i] + + if ($arg.StartsWith('/p:TargetArchitecture=', [StringComparison]::OrdinalIgnoreCase) -or + $arg.StartsWith('-p:TargetArchitecture=', [StringComparison]::OrdinalIgnoreCase)) { + $hasTargetArchitecture = $true + } + + if ($arg.Equals('-platform', [StringComparison]::OrdinalIgnoreCase) -and + $i + 1 -lt $BuildArgs.Length -and + $BuildArgs[$i + 1].Equals('arm64', [StringComparison]::OrdinalIgnoreCase)) { + $isArm64Platform = $true + $i++ + continue + } + + if ($arg.Equals('/p:Platform=arm64', [StringComparison]::OrdinalIgnoreCase) -or + $arg.Equals('-p:Platform=arm64', [StringComparison]::OrdinalIgnoreCase)) { + $isArm64Platform = $true + continue + } + + $forwardArgs.Add($arg) +} + +if ($isArm64Platform) { + $useNativeTools = $false + + if (!$hasTargetArchitecture) { + $forwardArgs.Add('/p:TargetArchitecture=arm64') + } +} + +$buildScript = Join-Path $PSScriptRoot 'common\Build.ps1' +$baseArgs = @() + +if ($useNativeTools) { + $baseArgs += '-NativeToolsOnMachine' +} + +$processArgs = @( + '-ExecutionPolicy' + 'ByPass' + '-NoProfile' + '-File' + $buildScript +) + $baseArgs + @( + '-restore' + '-build' + '-bl' +) + $forwardArgs + +& powershell @processArgs +exit $LASTEXITCODE