Skip to content

Add Native AOT infrastructure for MSBuild evaluation - #55441

Merged
baronfel merged 8 commits into
mainfrom
baronfel-aot-msbuild-evaluation
Jul 28, 2026
Merged

Add Native AOT infrastructure for MSBuild evaluation#55441
baronfel merged 8 commits into
mainfrom
baronfel-aot-msbuild-evaluation

Conversation

@baronfel

@baronfel baronfel commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

  • Centralize versioned SDK path resolution in SdkPaths.SdkDirectory so the managed and Native AOT CLIs, forwarding apps, and SDK resolvers use the same probing logic.
  • Add reflection-friendly workload and NuGet SDK resolver registration infrastructure plus physical-project metadata evaluation support for Native AOT.
  • Extract the workload advertising-manifest services and include the workload/vulnerability update source closure needed by shared restore-based command code.
  • Keep AotSourceFiles.props limited to source/resource inputs, with shared dependencies and runtime configuration in AotDependencies.props.
  • Document SDK-root resolution and the Native AOT MSBuild evaluation boundary.

This is the infrastructure layer of a two-PR stack. It deliberately does not call MSBuildSdkResolverRegistration.Register() during Native AOT startup and does not enable any additional MSBuild-backed commands. Unsupported commands continue to fall through to the managed CLI, so the resolver/evaluation closure is not activated in the shipping native image by this PR.

Validation

  • dotnet-aot.csproj builds with no warnings or errors.
  • The managed dotnet.csproj builds with no warnings or errors.
  • The infrastructure Native AOT publish emits zero diagnostics with TrimmerSingleWarn=false.
  • Focused tests cover SDK-root forwarding, explicit resolver registration, project metadata evaluation, workload advertising updates, and SDK vulnerability cache behavior.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@baronfel
baronfel force-pushed the baronfel-aot-msbuild-evaluation branch from 7d2f5ec to 74cfea2 Compare July 24, 2026 17:49
@baronfel
baronfel force-pushed the baronfel-aot-msbuild-evaluation branch 5 times, most recently from 5a506fa to 7e04840 Compare July 27, 2026 21:44
baronfel and others added 2 commits July 28, 2026 09:41
Route MSBuild forwarding and workload resolver probes through SdkPaths so managed and Native AOT hosts consistently resolve the selected versioned SDK directory.

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

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
@baronfel
baronfel force-pushed the baronfel-aot-msbuild-evaluation branch from 7e04840 to e54780c Compare July 28, 2026 14:46
@baronfel baronfel changed the title Enable MSBuild-backed commands in the Native AOT CLI Add Native AOT infrastructure for MSBuild evaluation Jul 28, 2026
@baronfel
baronfel requested a review from JeremyKuhne July 28, 2026 14:48
baronfel added 4 commits July 28, 2026 10:31
Compile the existing MsbuildProject and completion paths into the Native AOT CLI so command completions can evaluate configurations and target frameworks from the current project.

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

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
Add the shared workload advertising, NuGet download and signing, MSI extraction, and SDK vulnerability services to the Native AOT closure. Cover the closure directly so restoring commands can use the unchanged shared RestoringCommand as they are enabled.

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

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
Describe static SDK resolver registration, versioned SDK path requirements, physical pack behavior, directive-free virtual evaluation, workload maintenance parity, and managed fallback boundaries.

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

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
@baronfel
baronfel force-pushed the baronfel-aot-msbuild-evaluation branch from e54780c to d3dde07 Compare July 28, 2026 15:34

@JeremyKuhne JeremyKuhne 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.

Couple of project file comments

Comment thread src/Cli/dotnet-aot/dotnet-aot.csproj
Comment thread src/Cli/dotnet-aot/dotnet-aot.csproj Outdated
Comment thread src/Cli/dotnet/Commands/Workload/WorkloadInstallDetector.cs Outdated
@baronfel
baronfel marked this pull request as ready for review July 28, 2026 16:56
@baronfel
baronfel requested a review from a team as a code owner July 28, 2026 16:56
Copilot AI review requested due to automatic review settings July 28, 2026 16:56
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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 lays down infrastructure for Native AOT scenarios that need consistent SDK-root probing and a reflection-free MSBuild evaluation setup, while keeping the shipping AOT entry point behavior unchanged (still defers unsupported commands to the managed CLI).

Changes:

  • Centralizes versioned SDK directory resolution via SdkPaths.SdkDirectory and updates forwarding/resolver call sites to use it.
  • Introduces Native AOT-friendly MSBuild SDK resolver registration scaffolding and adds tests that validate in-process evaluation against a versioned SDK layout.
  • Extracts lightweight workload advertising-manifest update/installer components (file-based + MSI) and adjusts workload record detection to use read-only Windows record access.

Reviewed changes

Copilot reviewed 45 out of 45 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/dotnet.Tests/dotnet.Tests.csproj Excludes the new Windows-only MSI manifest installer test on non-Windows builds.
test/dotnet.Tests/CommandTests/Workload/Install/GivenAWindowsMsiManifestInstaller.cs Adds focused tests for MSI manifest package ID computation (Windows-only).
test/dotnet.Tests/CommandTests/Workload/Install/GivenAFileBasedManifestInstaller.cs Adds focused tests for file-based manifest installer behavior (ID computation + extraction).
test/dotnet-aot.Tests/WorkloadUpdateTests.cs Adds AOT test coverage for background workload advertising updates and vulnerability cache behavior.
test/dotnet-aot.Tests/WorkloadInstallDetectorTests.cs Updates detector tests to use the new read-only Windows workload record repository.
test/dotnet-aot.Tests/run-aot-tests.sh Plumbs bootstrap SDK directory into AOT tests via DOTNET_AOT_TEST_SDK_DIRECTORY and exports DOTNET_HOST_PATH.
test/dotnet-aot.Tests/run-aot-tests.ps1 Same as bash script, with try/finally restoring environment variables.
test/dotnet-aot.Tests/MSBuildEvaluationTests.cs Adds AOT tests for resolver registration, SDK-root forwarding, and MSBuild evaluation (properties-only).
test/dotnet-aot.Tests/dotnet-aot.Tests.csproj Links in AOT resolver registration source and adds resolver project reference for tests.
src/Resolvers/Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver/WorkloadSdkResolver.cs Switches SDK directory probing to SdkPaths.SdkDirectory for consistent probing.
src/Resolvers/Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver/Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.csproj Links SdkPaths.cs for .NET Framework builds of the resolver.
src/Resolvers/Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver/CachingWorkloadResolver.cs Uses SdkPaths.SdkDirectory for sentinel discovery instead of assembly location.
src/Resolvers/Microsoft.DotNet.MSBuildSdkResolver/Microsoft.DotNet.MSBuildSdkResolver.csproj Links SdkPaths.cs into the resolver closure.
src/Cli/Microsoft.DotNet.Cli.Utils/MSBuildForwardingAppWithoutLogging.cs Uses SdkPaths.SdkDirectory for MSBuild/Sdks path wiring and MSBuildExtensionsPath.
src/Cli/Microsoft.DotNet.Cli.CoreUtils/SdkPaths.cs Adds SDK directory caching + test hook, and trims trailing separators during resolution.
src/Cli/Microsoft.DotNet.Cli.CoreUtils/Microsoft.DotNet.Cli.CoreUtils.csproj Expands InternalsVisibleTo to allow new call sites to use SdkPaths internals.
src/Cli/dotnet/MsbuildProject.cs Removes CLI_AOT gating and fixes DOTNET_HOST_PATH restore behavior during evaluation.
src/Cli/dotnet/Installer/Windows/MsiPayload.cs Switches MSI manifest JSON deserialization to a dedicated STJ source-gen context.
src/Cli/dotnet/Installer/Windows/MsiPackageData.cs Extracts reusable helper for locating MSI payload via msi.json.
src/Cli/dotnet/Installer/Windows/MsiPackageCache.cs Uses MsiPackageData and switches to the new JSON serializer context.
src/Cli/dotnet/Installer/Windows/MsiManifestJsonSerializerContext.cs Adds dedicated STJ source-gen context for MsiManifest.
src/Cli/dotnet/Installer/Windows/InstallerJsonSerializerContext.cs Removes MsiManifest from the installer message serializer context.
src/Cli/dotnet/dotnet.csproj Excludes WindowsMsiManifestInstaller.cs from non-Windows builds.
src/Cli/dotnet/Commands/Workload/WorkloadInstallDetector.cs Refactors file-based record location logic into a shared factory and uses read-only Windows record repo.
src/Cli/dotnet/Commands/Workload/WorkloadInfoHelper.cs Reuses the shared file-based record factory and read-only Windows record repo in AOT paths.
src/Cli/dotnet/Commands/Workload/SIGNING-VERIFICATION.md Updates documentation to reflect the new lightweight advertising updater construction path.
src/Cli/dotnet/Commands/Workload/Install/WorkloadManifestUpdater.Managed.cs Rehomes managed implementation into a partial, delegating advertising to the extracted updater.
src/Cli/dotnet/Commands/Workload/Install/WorkloadManifestUpdater.cs Leaves shared entrypoints for background advertising updates and routes to WorkloadAdvertisingManifestUpdater.
src/Cli/dotnet/Commands/Workload/Install/WorkloadInstallRecords/ReadOnlyWindowsWorkloadInstallationRecordRepository.cs Introduces a read-only Windows workload record repository + reader.
src/Cli/dotnet/Commands/Workload/Install/WorkloadAdvertisingManifestUpdater.cs Extracts shared advertising manifest update logic used by both managed and AOT closures.
src/Cli/dotnet/Commands/Workload/Install/WindowsMsiManifestInstaller.cs Extracts MSI manifest installer logic out of the full MSI installer client for lightweight consumers.
src/Cli/dotnet/Commands/Workload/Install/NetSdkMsiInstallerClient.cs Delegates manifest package ID/extraction behavior to WindowsMsiManifestInstaller.
src/Cli/dotnet/Commands/Workload/Install/ManifestUpdateWithWorkloads.cs Moves the record type into its own file (no longer nested in the interface file).
src/Cli/dotnet/Commands/Workload/Install/IWorkloadManifestUpdater.cs Removes the nested record definition.
src/Cli/dotnet/Commands/Workload/Install/IWorkloadManifestInstaller.cs Introduces a standalone manifest installer abstraction for file/MSI implementations.
src/Cli/dotnet/Commands/Workload/Install/IInstaller.cs Removes the old embedded IWorkloadManifestInstaller definition.
src/Cli/dotnet/Commands/Workload/Install/FileBasedManifestInstaller.cs Extracts file-based manifest package ID and extraction behavior for lightweight consumers.
src/Cli/dotnet/Commands/Workload/Install/FileBasedInstaller.cs Delegates manifest package ID/extraction behavior to FileBasedManifestInstaller.
src/Cli/dotnet/Commands/MSBuild/MSBuildForwardingApp.cs Uses SdkPaths.SdkDirectory to locate dotnet.dll for telemetry logger injection.
src/Cli/dotnet/Commands/DotNetCommandFactory.cs Excludes virtual/physical command creation APIs from the AOT build.
src/Cli/dotnet-aot/SdkRootResolution.md Documents redist layout expectations and the unified SDK-directory probing behavior.
src/Cli/dotnet-aot/MSBuildSdkResolverRegistration.cs Adds explicit registration of workload + NuGet SDK resolvers for AOT in-process evaluation.
src/Cli/dotnet-aot/dotnet-aot.csproj Adjusts AOT warning severity policy and includes resolver registration source.
src/Cli/dotnet-aot/DESIGN.md Updates architecture/design docs to emphasize muxer integration and MSBuild evaluation boundary.
src/Cli/dotnet-aot/AotSourceFiles.props Expands the AOT closure to include resolver + advertising/vulnerability update sources and NuGet feature switch.
Comments suppressed due to low confidence (1)

src/Cli/dotnet/Commands/Workload/Install/WorkloadAdvertisingManifestUpdater.cs:115

  • The directory creation guard is inverted: this only calls Directory.CreateDirectory when the directory already exists, and skips it when it doesn't. Since Directory.CreateDirectory is idempotent, you can just call it unconditionally (or check for !Exists).
        if (Directory.Exists(Path.GetDirectoryName(filePath)))
        {
            Directory.CreateDirectory(Path.GetDirectoryName(filePath)!);
        }
        File.WriteAllText(filePath, jsonContent);

Comment thread src/Cli/dotnet/Commands/Workload/Install/WorkloadAdvertisingManifestUpdater.cs Outdated
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 54c93774-3a89-47a1-a53a-14dbdd71a0c8
@baronfel
baronfel merged commit 731cd08 into main Jul 28, 2026
22 checks passed
@baronfel
baronfel deleted the baronfel-aot-msbuild-evaluation branch July 28, 2026 21:05
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Jul 29, 2026
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.

3 participants