Repository navigation
Port first-run experience to the NativeAOT CLI entrypoint - #54970
Merged
Merged
Conversation
Continues the AOT dotnet CLI arc by bringing the cross-cutting "first run" experience - previously only implemented in the managed Program.cs - to the NativeAOT entrypoint, and aligns the two entrypoints structurally so parity is easy to verify. Highlights: - Extract the first-run logic into a shared FirstRunExperience.cs used by both the managed CLI and the AOT bridge (NativeEntryPoint), instead of living in Program.cs. - Extract the shared in-process command invocation into CommandInvocation.ExecuteInternalCommand so NativeEntryPoint no longer references Program. - Detect installed workloads in-process (WorkloadInstallDetector) by reusing the existing RegistryWorkloadInstallationRecordRepository read path; the elevation/MSI-IPC write members and InstallerBase are #if'd away for AOT rather than reimplemented. AOT only defers to the managed CLI when workload repair is actually pending. - Generate the ASP.NET Core HTTPS developer certificate in-process on AOT (the CertificateManager uses only BCL X509/RSA crypto; on macOS the crypto PAL resolves dynamically against the host's already-loaded native library). - Give dotnet-aot its own Program.cs entrypoint so the project no longer links the managed Program.cs; remove the now-dead #if CLI_AOT branches from the managed Program.cs. Update DESIGN.md accordingly. AOT publish (full ILC) is warning-free; the AOT test suite passes (77 passed, 6 skipped - the 6 require the AOT dn binary which isn't built in Debug). Co-authored-by: Copilot <[email protected]>
dotnet-aot is a NativeLib=Shared library whose entry points are the [UnmanagedCallersOnly] exports in NativeEntryPoint; it does not need (and never invoked) a managed Program.Main. Remove the project-local Program.cs rather than giving the AOT binary its own entry-point type. The managed dotnet.dll keeps its own Program.cs (used by the hostfxr fallback path). Update DESIGN.md to match. Verified: AOT build + full ILC publish are warning-free without any Program.cs, and the AOT test suite still passes (77 passed, 6 skipped). Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR ports the cross-cutting “first-run experience” from the managed dotnet entrypoint to the NativeAOT entrypoint by extracting shared logic into reusable helpers, so the AOT path can run first-run setup in-process and only fall back to managed hosting when workload repair is actually needed.
Changes:
- Extract first-run setup into
FirstRunExperienceand use it from bothProgram(managed) andNativeEntryPoint(AOT). - Extract in-process command invocation into
CommandInvocation.ExecuteInternalCommandto keep exit-code/exception handling in parity across entrypoints. - Add in-process workload-install detection (
WorkloadInstallDetector) and enable AOT-safe registry read support, with new tests covering the detector.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/dotnet-aot.Tests/WorkloadInstallDetectorTests.cs | Adds tests for file-based and registry-based workload record detection used by the AOT first-run path. |
| test/dotnet-aot.Tests/dotnet-aot.Tests.csproj | Adds reference needed for SdkFeatureBand/WorkloadInstallType usage in new detector tests. |
| src/Cli/dotnet/Program.cs | Switches managed entrypoint to shared FirstRunExperience + shared internal command invocation helper. |
| src/Cli/dotnet/FirstRunExperience.cs | New shared implementation of first-run setup used by both managed and AOT entrypoints. |
| src/Cli/dotnet/Commands/Workload/WorkloadInstallDetector.cs | New lightweight in-process detection of installed workloads (file/registry) for the current feature band. |
| src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallRecords/RegistryWorkloadInstallationRecordRepository.cs | Enables read-only AOT compilation path while #if’ing away elevation/MSI-IPC write paths. |
| src/Cli/dotnet/CommandInvocation.cs | New shared internal-command invocation logic (exit codes + exception handling parity). |
| src/Cli/dotnet-aot/NativeEntryPoint.cs | Runs shared first-run setup and shared invocation logic before deciding whether to fall back to managed hosting. |
| src/Cli/dotnet-aot/dotnet-aot.csproj | Stops linking managed Program.cs and adds reference needed for in-process workload install detection. |
| src/Cli/dotnet-aot/DESIGN.md | Updates design docs to reflect the new entrypoint split and shared helpers. |
| src/Cli/dotnet-aot/AotSourceFiles.props | Links new shared first-run/invocation/workload-detection sources into the AOT build and adds dev-cert package reference. |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
JeremyKuhne
approved these changes
Jun 29, 2026
JeremyKuhne
approved these changes
Jun 29, 2026
baronfel
enabled auto-merge (squash)
June 29, 2026 21:35
Member
Author
|
/ba-g flaky test |
This was referenced Jun 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Continues the AOT
dotnetCLI arc by bringing the cross-cutting first-run experience — previously implemented only in the managedProgram.cs— to the NativeAOT entrypoint, and aligns the two entrypoints structurally so parity is easy to verify.This is being opened to exercise the changes in CI (notably the AOT publish/test legs across platforms).
What's here
src/Cli/dotnet/FirstRunExperience.cs, used by both the managed CLI and the AOT bridge (NativeEntryPoint), instead of living inline inProgram.cs.CommandInvocation.ExecuteInternalCommandsoNativeEntryPointno longer referencesProgram. Both entrypoints call the same method.WorkloadInstallDetectordetects installed workloads in-process by reusing the existingRegistryWorkloadInstallationRecordRepositoryread path. The elevation/MSI-IPC write members andInstallerBaseare#if'd away for AOT rather than reimplemented. The AOT first run now only defers to the managed CLI when workload repair is actually pending.CertificateManageruses only BCL X509/RSA crypto (no reflection/dynamic code); on macOS the crypto PAL resolves dynamically against the host's already-loaded native library, so the existingRemoveAppleCryptoFromNativeAotLinkworkaround is preserved.Program.csin dotnet-aot.dotnet-aotis aNativeLib=Sharedlibrary whose entry points are the[UnmanagedCallersOnly]exports inNativeEntryPoint— it never invoked a managedProgram.Main, so the linked managedProgram.csis dropped entirely (not replaced with a project-local one). The manageddotnet.dllkeeps its ownProgram.cs(used by the hostfxr fallback path), with the now-dead#if CLI_AOTbranches removed.DESIGN.mdupdated to match.Validation (local, Windows)
Program.cs): 0 warnings / 0 errors — no IL2026/IL3050.dnbinary isn't built in Debug).AOT size impact
Measured by publishing
dotnet-aot(Release,win-x64, full ILC) on this branch vs. the PR base commit (793ebf24), then diffing thedotnet-aot.mstatfiles withsizoscope-cli(same methodology as.github/workflows/aot-size-analysis.yml).dotnet-aot.dll793ebf24)sizoscope-cliaccounted difference: +490.7 kB, attributable entirely to the first-run features ported in-process:System.Security.CryptographySystem.Private.CoreLibSystem.Security.AccessControlSystem.LinqMicrosoft.AspNetCore.DeveloperCertificates.XPlatSystem.Formats.Asn1System.Security.Principal.WindowsMicrosoft.Deployment.DotNet.ReleasesMicrosoft.NET.Sdk.WorkloadManifestReaderNuGet.Common/Cli.Utils/Configurer/Win32.RegistryThe large
*.resourcesrows in the rawsizoscopeoutput appear with equal+/−magnitudes (localized satellites re-attributed across builds) and net to ~zero — which is why the accounted total (490.7 kB) is below the raw file delta (606 kB). No unexpected dependencies were pulled in.Notes for reviewers
/usr/bin/security import+ dynamic crypto PAL resolution with the static archive removed) compiles AOT-clean but could not be runtime-validated locally on Windows — this PR is partly here to validate that on macOS CI.Co-authored-by: Copilot [email protected]