Skip to content

Port first-run experience to the NativeAOT CLI entrypoint - #54970

Merged
baronfel merged 5 commits into
mainfrom
baronfel-aot-cli-entrypoint-inventory
Jun 30, 2026
Merged

baronfel merged 5 commits into
mainfrom
baronfel-aot-cli-entrypoint-inventory

Conversation

@baronfel

@baronfel baronfel commented Jun 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Continues the AOT dotnet CLI arc by bringing the cross-cutting first-run experience — previously implemented only in the managed Program.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

  • Shared first-run logic. Extract the first-run experience into src/Cli/dotnet/FirstRunExperience.cs, used by both the managed CLI and the AOT bridge (NativeEntryPoint), instead of living inline in Program.cs.
  • Shared command invocation. Extract the in-process command invocation into CommandInvocation.ExecuteInternalCommand so NativeEntryPoint no longer references Program. Both entrypoints call the same method.
  • In-process workload detection. WorkloadInstallDetector detects installed workloads in-process by reusing the existing RegistryWorkloadInstallationRecordRepository read path. The elevation/MSI-IPC write members and InstallerBase are #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.
  • In-process dev-cert generation on AOT. Generate the ASP.NET Core HTTPS developer certificate in-process under NativeAOT. The CertificateManager uses 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 existing RemoveAppleCryptoFromNativeAotLink workaround is preserved.
  • No Program.cs in dotnet-aot. dotnet-aot is a NativeLib=Shared library whose entry points are the [UnmanagedCallersOnly] exports in NativeEntryPoint — it never invoked a managed Program.Main, so the linked managed Program.cs is dropped entirely (not replaced with a project-local one). The managed dotnet.dll keeps its own Program.cs (used by the hostfxr fallback path), with the now-dead #if CLI_AOT branches removed. DESIGN.md updated to match.

Validation (local, Windows)

  • AOT, managed CLI, and AOT test builds: 0 warnings / 0 errors.
  • AOT publish (full ILC native codegen, with no Program.cs): 0 warnings / 0 errors — no IL2026/IL3050.
  • AOT test suite: 77 passed / 6 skipped / 0 failed (the 6 skip because the AOT dn binary 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 the dotnet-aot.mstat files with sizoscope-cli (same methodology as .github/workflows/aot-size-analysis.yml).

Native dotnet-aot.dll Size
Base (793ebf24) 16.846 MB (17,664,000 B)
This PR 17.438 MB (18,285,056 B)
Delta +606 KB (+3.52%)

sizoscope-cli accounted difference: +490.7 kB, attributable entirely to the first-run features ported in-process:

Contributor Δ Reason
System.Security.Cryptography +133.1 kB dev-cert generation
System.Private.CoreLib +120 kB crypto/registry surface
System.Security.AccessControl +39.0 kB registry ACL read
System.Linq +18.5 kB detection/cert code
Microsoft.AspNetCore.DeveloperCertificates.XPlat +15.8 kB cert generator package
System.Formats.Asn1 +9.5 kB cert encoding
System.Security.Principal.Windows +8.6 kB registry identity
Microsoft.Deployment.DotNet.Releases +6.7 kB workload band detection
Microsoft.NET.Sdk.WorkloadManifestReader +5.6 kB workload detection
NuGet.Common / Cli.Utils / Configurer / Win32.Registry ~11 kB workload record repo reuse

The large *.resources rows in the raw sizoscope output 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

  • The macOS runtime cert path (/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]

baronfel and others added 2 commits June 24, 2026 19:28
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]>
@baronfel
baronfel marked this pull request as ready for review June 25, 2026 02:40
Copilot AI review requested due to automatic review settings June 25, 2026 02:40

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 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 FirstRunExperience and use it from both Program (managed) and NativeEntryPoint (AOT).
  • Extract in-process command invocation into CommandInvocation.ExecuteInternalCommand to 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.

@baronfel
baronfel requested a review from JeremyKuhne June 25, 2026 14:44
@baronfel baronfel added the Area-dotnet AOT Items that are part of the dotnet CLI AOT-ification effort label Jun 25, 2026
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@baronfel
baronfel enabled auto-merge (squash) June 29, 2026 21:35
@baronfel

Copy link
Copy Markdown
Member Author

/ba-g flaky test

@baronfel
baronfel merged commit 764feec into main Jun 30, 2026
24 of 26 checks passed
@baronfel
baronfel deleted the baronfel-aot-cli-entrypoint-inventory branch June 30, 2026 02:01
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-dotnet AOT Items that are part of the dotnet CLI AOT-ification effort

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants