Enable 'dotnet sdk check' command in AOT native binary#54391
Open
NikolaMilosavljevic wants to merge 3 commits into
Open
Enable 'dotnet sdk check' command in AOT native binary#54391NikolaMilosavljevic wants to merge 3 commits into
NikolaMilosavljevic wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enables the dotnet sdk check command to run via the NativeAOT-compiled CLI fast-path, threading the host-provided DOTNET_ROOT into the command and hardening the unmanaged entry point so managed exceptions cannot escape across the boundary.
Changes:
- Registers
sdk checkin the AOT-only parser and wires it toSdkCheckCommand.Run. - Extends the
dotnet-aotproject to compile/link thesdk checkimplementation and embed required.resxresources plus theMicrosoft.Deployment.DotNet.Releasesdependency. - Refactors the AOT native entry point to wrap the full
[UnmanagedCallersOnly]method body in a top-level try/catch, and introducesProgram.DotnetRoot(AOT-only) for passing the dotnet root into commands.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/dotnet/Program.cs | Adds AOT-only DotnetRoot and wraps AOT Main in error handling. |
| src/Cli/dotnet/Parser.cs | Registers sdk check under the AOT parser. |
| src/Cli/dotnet/Commands/Sdk/Check/SdkCheckCommand.cs | Adds AOT conditional wiring to pass Program.DotnetRoot and adjusts aliasing for AOT builds. |
| src/Cli/dotnet/CommandBase.cs | Guards help/error extension usage for AOT builds. |
| src/Cli/dotnet-aot/NativeEntryPoint.cs | Extracts ExecuteCore and wraps the unmanaged entry point body with a top-level try/catch; sets Program.DotnetRoot for the AOT fast-path. |
| src/Cli/dotnet-aot/dotnet-aot.csproj | Includes sdk check sources/resources and adds Microsoft.Deployment.DotNet.Releases package reference. |
Comments suppressed due to low confidence (1)
src/Cli/dotnet/Parser.cs:37
- This error message is hard-coded even though a localized resource exists (
CliStrings.RequiredCommandNotPassed). Please use the resource string here to keep messages consistent and localizable (and sinceCliStrings.resxis embedded for AOT in this PR).
sdkCommand.SetAction(parseResult =>
{
parseResult.InvocationConfiguration.Error.WriteLine("Required command was not provided.");
return 1;
Add the sdk check command to the AOT-compiled CLI binary (dotnet-aot.csproj). This command lists installed SDKs and runtimes and checks for updates, performing all work in-process without MSBuild or NuGet dependencies. Changes: - Register 'sdk check' command in the AOT Parser.cs section - Add exception handling in both Program.Main and NativeEntryPoint for GracefulException and unexpected errors - Thread dotnetRoot from native host into SdkCheckCommand to ensure the correct .NET installation is inspected - Guard CommandBase.ShowHelpOrErrorIfAppropriate with #if !CLI_AOT (extension method references types unavailable in AOT) - Handle extern alias for EnvironmentProvider conditionally in SdkCheckCommand (#if CLI_AOT uses direct reference) - Add Compile items, EmbeddedResource items (CliStrings.resx, CliCommandStrings.resx), and Microsoft.Deployment.DotNet.Releases package reference to dotnet-aot.csproj Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Enables the
dotnet sdk checkcommand to run in the AOT-compiled native CLI binary, improving cold-start performance for this command.Changes
sdk checkcommand in the#if CLI_AOTsection withSdkCheckCommand.RunactionMicrosoft.Deployment.DotNet.Releasespackage referenceExecuteCoremethod so the entire[UnmanagedCallersOnly]entry point body is wrapped in a top-level try/catch — no managed exception can cross the unmanaged boundary. Also setsProgram.DotnetRootand adds inner exception handling for AOT invoke path.Program.DotnetRootstatic property (AOT-only) to thread host-provided dotnet root to commands; add try/catch inMainParseResultExtensionsimport andShowHelpOrErrorIfAppropriatecall with#if !CLI_AOT(these depend on types not available in AOT build)extern alias, conditionalEnvironmentProviderusing, threadProgram.DotnetRootin AOT pathDesign Decisions
sdk checkwas chosen as the first new AOT command because it has zero MSBuild/NuGet dependencies and does all work in-process (HTTP fetch + JSON parsing + table formatting)Microsoft.Deployment.DotNet.ReleasesusesJsonDocumentDOM API (no reflection) — verified AOT-safeCliStrings.resxandCliCommandStrings.resxare embedded (size tradeoff for simplicity over splitting ~20 needed strings)NativeEntryPoint.Executewraps the entire method body in try/catch since[UnmanagedCallersOnly]methods must never let managed exceptions escapeKnown Compromises
dotnet sdk(bare) shows minimal System.CommandLine error vs full help in non-AOTTesting