Skip to content

Make bundled tools from dotnet/aspnetcore native AOT - #6720

Merged
DamianEdwards merged 18 commits into
mainfrom
damianedwards/user-secrets-aot
May 22, 2026
Merged

DamianEdwards merged 18 commits into
mainfrom
damianedwards/user-secrets-aot

Conversation

@DamianEdwards

@DamianEdwards DamianEdwards commented May 20, 2026 •

Copy link
Copy Markdown
Member

This updates the tools bundled into the SDK from dotnet/aspnetcore to be published native AOT. Adds coarse-grained smoke tests that exercise the main functionality of the tools after they've been published.

Tools effected:

  • dotnet user-secrets
  • dotnet user-jwts
  • dotnet dev-certs

The published size of each tool locally on win-x64 is:

Tool Published size
dotnet-user-secrets 3.94 MB
dotnet-user-jwts 5.36 MB
dotnet-dev-certs 3.04 MB

Port the effective changes from dotnet/aspnetcore#66663 into the VMR.

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 20, 2026 17:37
Select the RID-specific dotnet-user-secrets package for SDK layout and teach the bundled tool resolver to honor DotnetToolSettings.xml executable runners.

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 20, 2026 17:55

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some thoughts on how we should do this better

Move bundled tool package download selection into a restore target and use SelectRuntimeIdentifierSpecificItems to choose the dotnet-user-secrets RID package.

Co-authored-by: Copilot <[email protected]>
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 20, 2026 18:24
DamianEdwards and others added 5 commits May 20, 2026 11:53
Keep dotnet-user-secrets RID-specific package selection separate from the other bundled tools so dev-certs and user-jwts continue to lay out under any.

Co-authored-by: Copilot <[email protected]>
Use BundledDotnetTool metadata to opt tools into RID-specific package selection, so future ASP.NET Core bundled tools can move to Native AOT without adding package-specific layout logic.

Co-authored-by: Copilot <[email protected]>
Enable Native AOT publishing for dotnet-dev-certs, move shared bundled tool AOT defaults into the tools build, and mark dev-certs as a RID-specific bundled SDK tool package.

Co-authored-by: Copilot <[email protected]>
Enable Native AOT publishing for dotnet-user-jwts, use source-generated JSON metadata for its serialization paths, and mark it as a RID-specific bundled SDK tool package.

Co-authored-by: Copilot <[email protected]>
@DamianEdwards DamianEdwards changed the title Make dotnet-user-secrets Native AOT compatible Make bundled tools from dotnet/aspnetcore Native AOT compatible May 20, 2026
@DamianEdwards
DamianEdwards marked this pull request as ready for review May 20, 2026 22:50
Copilot AI review requested due to automatic review settings May 20, 2026 22:50
@DamianEdwards DamianEdwards changed the title Make bundled tools from dotnet/aspnetcore Native AOT compatible Make bundled tools from dotnet/aspnetcore native AOT May 20, 2026
@DamianEdwards
DamianEdwards requested a review from eerhardt May 20, 2026 22:53

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.

Pull request overview

This PR updates the ASP.NET Core CLI tools that are bundled into the .NET SDK (dotnet-user-secrets, dotnet-user-jwts, dotnet-dev-certs) to be Native AOT compatible, primarily by switching tool JSON usage to source-generated serializers and by updating the SDK layout logic to prefer RID-specific tool packages. It also adds new smoke tests that publish the tools as Native AOT and validate a few end-to-end scenarios.

Changes:

  • Update SDK tool layout to select RID-specific AspNetCore tool packages when available and add the selected packages as PackageDownload items.
  • Make the three tools Native AOT-friendly (source-generated System.Text.Json contexts, PublishAot=true, and a single-file Assembly.Location fallback fix).
  • Add new Native AOT publish + smoke tests that run the published executables.

Reviewed changes

Copilot reviewed 25 out of 25 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/sdk/test/dotnet.Tests/CommandFactoryTests/GivenADotnetToolsCommandResolver.cs Adds a unit test covering executable-based tools via DotnetToolSettings.xml.
src/sdk/src/Layout/redist/targets/BundledDotnetTools.targets Selects RID-specific tool packages and wires them into PackageDownload + layout copy.
src/sdk/src/Cli/dotnet/CommandFactory/CommandResolution/DotnetToolsCommandResolver.cs Adds support for resolving executable tools via DotnetToolSettings.xml.
src/aspnetcore/src/Tools/Tools.slnf Includes the new Native AOT test project in the tool solution filter.
src/aspnetcore/src/Tools/Shared/TestHelpers/NativeAotToolRunner.cs New helper to execute published Native AOT tool binaries with timeout + isolated profile env.
src/aspnetcore/src/Tools/Shared/SecretsHelpers/ProjectIdResolver.cs Adjusts SecretManager.targets discovery for single-file/AOT scenarios.
src/aspnetcore/src/Tools/NativeAot/test/NativeAotToolScenarioTests.cs Adds end-to-end smoke scenarios for user-secrets/user-jwts/dev-certs.
src/aspnetcore/src/Tools/NativeAot/test/NativeAotToolEntryPointTests.cs Adds “entry point runs/--help works” coverage for the published tools.
src/aspnetcore/src/Tools/NativeAot/test/Microsoft.AspNetCore.Tools.NativeAot.Tests.csproj New test project that publishes tools as Native AOT before running tests; ships outputs to Helix.
src/aspnetcore/src/Tools/dotnet-user-secrets/src/Internal/SecretsStore.cs Switches secrets JSON serialization to source-generated context (AOT-friendly).
src/aspnetcore/src/Tools/dotnet-user-secrets/src/Internal/ListCommand.cs Uses the new SecretsStore.Serialize helper for JSON output.
src/aspnetcore/src/Tools/dotnet-user-secrets/src/dotnet-user-secrets.csproj Enables PublishAot for the tool project.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Helpers/SigningKeysHandler.cs Switches JSON nodes/serialization to source-generated context APIs.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Helpers/JwtStore.cs Switches JWT store JSON read/write to source-generated context.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Helpers/JwtSerializerOptions.cs Adds a JsonSerializerContext for source-generated serialization.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Helpers/JwtAuthenticationSchemeSettings.cs Uses source-generated context for appsettings JSON manipulation.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Helpers/DevJwtCliHelpers.cs Uses source-generated context for JSON output.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/dotnet-user-jwts.csproj Enables PublishAot for the tool project.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Commands/ListCommand.cs Uses source-generated context for JSON output.
src/aspnetcore/src/Tools/dotnet-user-jwts/src/Commands/CreateCommand.cs Uses source-generated context for JSON output.
src/aspnetcore/src/Tools/dotnet-dev-certs/src/Program.cs Switches cert report JSON output to source-generated context; adjusts DTO for serialization.
src/aspnetcore/src/Tools/dotnet-dev-certs/src/dotnet-dev-certs.csproj Enables PublishAot for the tool project.
src/aspnetcore/src/Tools/Directory.Build.targets Adds AOT-specific tool build settings and disables AOT for source-only builds.
src/aspnetcore/src/Tools/Directory.Build.props Defines the RID set used for bundled tool publishing.
src/aspnetcore/AspNetCore.slnx Adds the new Native AOT test project to the main solution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@BrennanConroy BrennanConroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Generally good, some other folks should look closer at the msbuild and tool invocation change.

DamianEdwards and others added 3 commits May 20, 2026 17:42
Guard Native AOT tool publishing in source-only builds before restore evaluation and restore RID-specific bundled tool packages using the current ASP.NET Core package version.

Co-authored-by: Copilot <[email protected]>
DamianEdwards and others added 5 commits May 21, 2026 15:23
Set RuntimeIdentifiers next to PublishAot so source-only builds avoid AOT restore inference and regular builds expose the RID list before SDK runtime identifier inference.

Co-authored-by: Copilot <[email protected]>
Move PublishAot and RuntimeIdentifiers into a dedicated source-build-gated property group for each bundled tool project.

Co-authored-by: Copilot <[email protected]>

@baronfel baronfel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The tool resolver changes are good on the SDK side of things, thanks for plumbing this through!

@DamianEdwards
DamianEdwards enabled auto-merge May 22, 2026 20:45
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 22, 2026 20:45
@DamianEdwards
DamianEdwards merged commit 821c533 into main May 22, 2026
11 checks passed
@DamianEdwards
DamianEdwards deleted the damianedwards/user-secrets-aot branch May 22, 2026 23:47
<UsingTask TaskName="Microsoft.NET.Build.Tasks.SelectRuntimeIdentifierSpecificItems" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

<PropertyGroup>
<AspNetCoreRidSpecificToolPackageRids>linux-x64;linux-arm;linux-arm64;linux-musl-x64;linux-musl-arm;linux-musl-arm64;win-x64;win-x86;win-arm64;osx-x64;osx-arm64</AspNetCoreRidSpecificToolPackageRids>

@am11 am11 May 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When we are building .NET for community platforms like linux-riscv64 or freebsd-arm64 (currently, there are nine of them), it should account for it. With the same token, those platforms tools aren't required in MSFT SDK.

IOW, we are missing "current target RID" in the list.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Opened follow-up PR: #6797

@lewing

lewing commented May 23, 2026

Copy link
Copy Markdown
Member

🚨 NativeAOT linker failure on musl/cross-build legs in VMR rolling builds

Since this PR merged, all internal main rolling builds are failing on 6 Linux legs with:

clang: error: invalid linker name in argument '-fuse-ld=bfd'
  [src/aspnetcore/src/Tools/dotnet-user-secrets/src/dotnet-user-secrets.csproj]

microsoft.dotnet.ilcompiler/11.0.0-preview.5.26272.119/build/Microsoft.NETCore.Native.targets(370,5):
  error MSB3073: The command "clang" ... -fuse-ld=bfd ... --target=aarch64-linux-musl ... exited with code 1.

Affected legs

Linux_Alpine_arm64, Linux_Alpine_x64, Linux_arm64, Linux_arm, Linux_Pgo_x64, Linux_Pgo_arm64 — all cross-compilation or musl targets.

Bisect

Last green: build 2981555 (sha 6fa530d, queued May 22 07:06 UTC)
First red: build 2982298 (sha 821c533, queued May 23 02:13 UTC) — first commit is this PR.

Cause

The NativeAOT ILCompiler passes -fuse-ld=bfd (GNU linker) when linking dotnet-user-secrets for linux-musl-arm64. But the VMR cross-compilation containers (AzureLinux) and Alpine containers don't have ld.bfd installed — they ship ld.lld (LLVM) or ld.mold.

Possible fixes

  1. Runtime: Change NativeAOT linker selection to prefer lld over bfd on musl targets (runtime team, Microsoft.NETCore.Native.targets)
  2. Infra: Install binutils (provides ld.bfd) in the cross-compilation container images (@dotnet/dnceng)
  3. Revert this PR until the linker issue is resolved

cc @DamianEdwards @MichalStrehovsky @am11

@am11

am11 commented May 23, 2026

Copy link
Copy Markdown
Member

Runtime: Change NativeAOT linker selection to prefer lld over bfd on musl targets (runtime team, Microsoft.NETCore.Native.targets)

This is our go-to way for official builds. You can just copy this target and it should work https://github.com/dotnet/runtime/blob/2dce83ad91efd1efbf974eb636a18f9b0fcdcb17/eng/toolAot.targets#L28C1-L48C12 (uses a script from arcade's eng/common so it's available everywhere)

PS -
lld is LLVM's linker, the default linker on linux is bfd. bfd comes from GNU binutils package, that is target specific (e.g. to build arm64 on x64, we need cross-arm64 binutils). lld, OTOH, is multi-target, so you can even link linux-riscv64 binary on win-x64 using lld.exe on windows and it would work.

@lewing

lewing commented May 23, 2026

Copy link
Copy Markdown
Member

Additional details on the -fuse-ld=bfd root cause

The NativeAOT linker flavor selection lives in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets:

<LinkerFlavor Condition="... and '$(_targetOS)' == 'freebsd'">lld</LinkerFlavor>
<LinkerFlavor Condition="... and '$(_linuxLibcFlavor)' == 'bionic'">lld</LinkerFlavor>
<LinkerFlavor Condition="... and '$(_targetOS)' == 'android'">lld</LinkerFlavor>
<LinkerFlavor Condition="... and '$(_targetOS)' == 'linux'">bfd</LinkerFlavor>  ← catches all linux including musl

There is no musl-specific override. All linux-musl-* targets fall through to the generic linux → bfd default, but the VMR cross-compilation containers (AzureLinux) don't have ld.bfd installed.

The runtime's own cross-build docs (src/coreclr/nativeaot/docs/containers.md) document the workaround: pass -p:LinkerFlavor=lld. The runtime's own eng/toolAot.targets also auto-detects LLD when available.

The fix would be adding a musl override in Microsoft.NETCore.Native.Unix.targets:

<LinkerFlavor Condition="'$(LinkerFlavor)' == '' and '$(_linuxLibcFlavor)' == 'musl'">lld</LinkerFlavor>

Short-term workaround for this PR: set <LinkerFlavor>lld</LinkerFlavor> in the aspnetcore tool csproj files for musl RIDs, or pass /p:LinkerFlavor=lld on cross-build legs.

Note: this PR was authored directly in dotnet/dotnet (not flowed from aspnetcore/runtime), so it was only tested by VMR PR validation — which does not include any Linux cross-build or musl legs. That's the coverage gap that allowed this to slip through.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants