Skip to content

Enhance ARM64 build scripts and architecture handling - #15314

Open
KlausLoeffelmann wants to merge 3 commits into
dotnet:mainfrom
KlausLoeffelmann:armFix-on-main
Open

KlausLoeffelmann wants to merge 3 commits into
dotnet:mainfrom
KlausLoeffelmann:armFix-on-main

Conversation

@KlausLoeffelmann

@KlausLoeffelmann KlausLoeffelmann commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

This pull request introduces robust support for Windows x64 and ARM64 builds, improving how the repository handles SDK and runtime architecture isolation, installation, and repair. The changes ensure that builds and restores work seamlessly across architectures, correctly manage mixed or reused SDK installations, and provide new scripts and documentation to clarify and automate these processes. The update also adds regression tests to verify architecture handling in CI.

Build and architecture handling improvements:

  • Added eng/dotnet-architecture.ps1, a comprehensive script for detecting, installing, and repairing .NET SDK and runtime installations across x64, ARM64, and x86 architectures, including logic for handling reused or mixed-architecture SDKs and preserving incomplete/incompatible runtimes (eng/dotnet-architecture.ps1).
  • Updated eng/configure-toolset.ps1 to use the new architecture detection and repair logic, ensuring that SDK installations match the host or specified architecture and are repaired as needed.
  • Added eng/install-runtimes.ps1, which installs required .NET runtimes for the correct architecture(s) and ensures all runtime files are present and compatible.
  • Introduced eng/Tools.props to bypass default Arcade SDK cache checks and invoke the repository’s own runtime installer, ensuring correct runtime isolation and installation for WinForms projects.

Build script and pipeline updates:

  • Replaced calls to Arcade’s Build.ps1 with a new eng/build.cmd.ps1 script in both build.cmd and Restore.cmd, which parses arguments, sets architecture defaults, and invokes the build with the correct configuration [1] [2] [3].
  • Updated Directory.Build.props to set the TargetArchitecture property based on platform and OS, ensuring builds default to the correct architecture unless explicitly overridden.

Documentation and CI enhancements:

  • Expanded docs/building.md with detailed guidance on Windows x64 and ARM64 builds, SDK/runtime installation behavior, and troubleshooting for mixed-architecture environments.
  • Added CI steps in eng/pipelines/build-PR.yml to run new regression tests that verify proper SDK and runtime architecture isolation.

These changes collectively improve cross-architecture support, reliability, and clarity for developers working with Windows .NET builds.

Microsoft Reviewers: Open in CodeFlow

KlausLoeffelmann and others added 2 commits October 26, 2026 12:33
- Switch build.cmd to use build.cmd.ps1 for improved argument parsing and ARM64 detection.
- Add logic to remove mismatched hostfxr.dll versions on ARM64, ensuring correct architecture resolution and self-healing builds.
- Pin CMake version to 3.21.0 in global.json for consistency.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 479cf8e8-6235-4ad2-8f8d-7d4bb931f24c
Separate OS, SDK execution, and target architectures to support native and cross-target builds on ARM64 and x64. Preserve compatible emulated SDKs, repair mixed runtime installations safely, and align restore and IDE launcher roots. Add regression checks to PR CI and document the architecture model.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved correctness issues affect architecture selection, runtime recovery and discovery, and build failure reporting.

7 open issues
What changed in this PR

This PR adds repository-owned architecture handling to WinForms build tooling, separating SDK execution architecture from build targets and runtime installations.

Changes:

  • Adds architecture-aware SDK selection, runtime installation, and mixed-installation repair.
  • Updates build wrappers, IDE launchers, and project defaults for x64, ARM64, and x86 targets.
  • Documents the workflow and adds script regression checks to PR CI.
File Description
start-vs.cmd Resolves SDK and runtime roots before launching Visual Studio.
start-code.cmd Configures architecture-specific roots for VS Code.
src/​test/​integration/​ScratchProject/​ScratchProject.csproj Derives the runtime identifier from the target architecture.
Restore.cmd Routes restore through the new wrapper.
global.json Prefers the host SDK location and generalizes runtime selection.
eng/​Tools.props Hooks the repository runtime installer into Arcade.
eng/​tests/​DotNetArchitecture.Tests.ps1 Tests SDK selection, runtime isolation, and repair.
eng/​tests/​BuildScript.Tests.ps1 Tests argument forwarding, architecture defaults, and exit codes.
eng/​pipelines/​build-PR.yml Runs the new script regression checks.
eng/​install-runtimes.ps1 Installs manifest runtimes for SDK and target architectures.
eng/​dotnet-architecture.ps1 Implements architecture detection, directory routing, and repair.
eng/​configure-toolset.ps1 Integrates architecture-aware SDK bootstrap with Arcade.
eng/​build.cmd.ps1 Handles build arguments and supplies architecture defaults.
docs/​building.md Documents architecture selection, isolation, and recovery.
Directory.Build.props Infers target architecture from platform and host settings.
build.cmd Invokes the new build wrapper.

Review effort: Balanced

return $dotnetRoot
}

return Join-Path $dotnetRoot $runtimeArchitecture
Comment thread Directory.Build.props Outdated
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<PublishWindowsPdb>false</PublishWindowsPdb>

<TargetArchitecture Condition="'$(TargetArchitecture)' == '' and ('$(Platform)' == 'arm64' or '$(Platform)' == 'x64' or '$(Platform)' == 'x86')">$(Platform)</TargetArchitecture>
Comment thread eng/build.cmd.ps1 Outdated
Comment on lines +23 to +33
if ($arg -match '^[-/]p:TargetArchitecture=') { $hasTargetArchitecture = $true }
if ($arg -match '^-(restore|r)$') { $hasRestore = $true }
if ($arg -match '^-(build|b)$') { $hasBuild = $true }
if ($arg -match '^-(binaryLog|bl|binaryLogName|bln|excludeCIBinarylog|nobl)$') { $hasBinaryLog = $true }

if ($arg -eq '-platform' -and $i + 1 -lt $BuildArgs.Length) {
$targetArchitecture = $BuildArgs[$i + 1]
}
elseif ($arg -match '^[-/]p:Platform=(.+)$') {
$targetArchitecture = $Matches[1]
}
Comment thread eng/build.cmd.ps1 Outdated
# -File cannot bind Boolean parameters in Windows PowerShell. Encode a command
# with quoted values and literal Boolean arguments instead of losing their types.
$buildScript = "$PSScriptRoot\common\build.ps1".Replace("'", "''")
$command = "`$ProgressPreference = 'SilentlyContinue'; & '$buildScript' -NativeToolsOnMachine"
Comment thread eng/dotnet-architecture.ps1 Outdated
Comment on lines +109 to +111
if (!(Test-Path -LiteralPath $binaryPath)) {
continue
}
Comment thread eng/dotnet-architecture.ps1 Outdated
Comment on lines +150 to +152
$complete = (Test-Path -LiteralPath $muxer) -and
(Test-Path -LiteralPath $coreclr) -and
(Test-Path -LiteralPath $resolver)
Comment thread start-vs.cmd Outdated
set DOTNET_ROOT(x86)=%~dp0.dotnet\x86
if defined DOTNET_GLOBAL_INSTALL_DIR set "DOTNET_ROOT=%DOTNET_GLOBAL_INSTALL_DIR%"
set "__DotNetSdkRoot="
for /f "delims=" %%r in ('powershell -NoProfile -ExecutionPolicy ByPass -File "%~dp0eng\dotnet-architecture.ps1" -ResolveSdkRoot "%DOTNET_ROOT%"') do set "__DotNetSdkRoot=%%r"
@codecov

codecov Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.84861%. Comparing base (c37f09d) to head (2362ebf).

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15314   +/-   ##
=============================================
  Coverage   37.84861%   37.84861%           
=============================================
  Files            246         246           
  Lines           9789        9789           
  Branches        1031        1031           
=============================================
  Hits            3705        3705           
  Misses          5920        5920           
  Partials         164         164           
Flag Coverage Δ
Debug 37.84861% <ø> (ø)
production 40.04608% <ø> (ø)
test 20.64923% <ø> (ø)
unit 40.04608% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Address ARM64 build review findings with architecture-specific apphost roots, reliable argument forwarding, runtime payload validation, and safe resolver repair. Add regression coverage for fresh installs and incomplete caches.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 60ae4767-5c06-4b45-ab0f-996e7d30e05a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants