Enable .NET SDK Native-AOT Compilation
Summary
Transform the .NET SDK into a Native-AOT compiled application to significantly reduce startup time and improve performance for every single use of the dotnet CLI.
Motivation
The .NET CLI is one of the most frequently used developer tools in the .NET ecosystem. Currently, each CLI invocation incurs approximately ~150ms of startup overhead due to the managed runtime initialization process. While this may seem insignificant for individual commands, the aggregate impact is substantial:
- Developer productivity: The cumulative delay across daily workflows significantly impacts developer experience
- Global scale impact: With billions of monthly invocations, even small improvements translate to massive time savings
- Resource efficiency: Reduced memory footprint and faster startup times benefit both local development and cloud-based build environments
By converting the .NET SDK to Native-AOT, we can eliminate most of this startup overhead, providing near-instantaneous command execution and dramatically improving the developer experience at scale. We can also showcase and encourage the adoption of Native AOT for CLI applications, and make the dotnet CLI an example of a best-in-class .NET CLI application all-up.
Scope and Approach
This Epic encompasses the technical work required to enable Native-AOT compilation of the .NET SDK, including infrastructure changes, library updates, and runtime integration modifications. The work will be executed in phases, starting with AOT compatibility enablement and culminating in a hybrid architecture where AOT handles command parsing while managed code handles complex operations.
Technical Implementation Strategy
Phase 1: Enable AOT Compatibility Analysis
Goal: Enable IsAotCompatible MSBuild property across the SDK repository to identify all AOT-incompatible code paths.
Phase 2: Resolve Core AOT Compatibility Issues
2.1 COM Interop Modernization
Problem: Current COM interop usage (e.g., DangerousFileDetector, VS workload manifest checking) uses reflection-based COM activation that's incompatible with AOT. There's a spike of what this might look like at #49669.
Solution: Migrate to source-generated COM interop
2.2 Telemetry Infrastructure Modernization
Problem: ApplicationInsights libraries are not AOT-compatible and never will be.
Solution: Migrate to OpenTelemetry + Azure Monitor OTel exporter - @MiYanni and I have this mostly working at #49409.
Tracking issue: #49668
2.3 JSON Handling Modernization
Problem: Dynamic JSON handling throughout the codebase needs to use System.Text.Json source generators for AOT compatibility.
Solution: Implement source-generated JSON serialization
NuGet Libraries: NuGet/Home#14408
Templating libraries: the template engine is built on top of Newtonsoft.Json - we need to migrate it to System.Text.Json and enable source generation by consumers.
SDK JSON Usage:
2.4 MSBuild Evaluation Infrastructure Changes
Problem: MSBuild evaluation requires pluggable, AOT-compatible infrastructure.
Solution: Create AOT-friendly MSBuild integration points
Tracking issue: dotnet/msbuild#12141
SdkResolver Infrastructure:
Property Function Evaluation:
2.5 Roslyn dependencies
The file-based apps feature set uses Roslyn APIs to do lexing, but those aren't AOT'd today. There's a WIP for enabling trimming over at dotnet/roslyn#66519 that would be a prerequisite here.
Phase 3: Runtime Integration
3.1 Muxer Integration
Goal: Modify the .NET Runtime muxer to invoke the AOT-compiled SDK when available.
3.2 Hybrid Architecture Implementation
Goal: Create a hybrid model where AOT handles command parsing and common operations, with managed code for complex scenarios.
Command Parsing Migration:
Command Handler Strategy:
Phase 4: Incremental Command Migration
4.1 Pure-AOT Commands (Phase 4a)
Commands that do not use any of the above tech can be migrated to native handlers immediately.
4.3 Out-of-Process MSBuild Commands (Phase 4c)
Commands that perform MSBuild builds only (no evaluation) can be migrated to out-of-process MSBuild invocations immediately - note that file-based apps currently always must be handled by managed code, because they do build execution via the MSBuild API directly.
4.2 Hybrid Commands (Phase 4b)
Commands that interact with NuGet/COM/MSBuild evaluation (which is most of them)
will need to wait until their associated blocker are migrated to AOT-compatible versions.
Partner Team Coordination
Dependencies on External Teams
.NET Runtime Team
NuGet Team
MSBuild Team
.NET Source-build Team
Success Metrics
Performance Targets
Quality Gates
Risks and Mitigations
Technical Risks
- AOT Limitations: Some dynamic scenarios may not be AOT-compatible
- Mitigation: Hybrid architecture with managed fallback
- Performance Regression: Complex operations might be slower in AOT
- Mitigation: Benchmark-driven development and selective AOT usage
- Compatibility Issues: Third-party integrations may break
- Mitigation: Extensive compatibility testing and partner engagement
Delivery Risks
- Cross-team Dependencies: Multiple teams must coordinate delivery
- Mitigation: Clear interface contracts and incremental integration
- Scope Creep: Additional AOT blockers discovered during implementation
- Mitigation: Phased approach with continuous blocker assessment
- Mitigation: Requirement to keep a managed fallback for all commands until AOT blockers are resolved
Enable .NET SDK Native-AOT Compilation
Summary
Transform the .NET SDK into a Native-AOT compiled application to significantly reduce startup time and improve performance for every single use of the
dotnetCLI.Motivation
The .NET CLI is one of the most frequently used developer tools in the .NET ecosystem. Currently, each CLI invocation incurs approximately ~150ms of startup overhead due to the managed runtime initialization process. While this may seem insignificant for individual commands, the aggregate impact is substantial:
By converting the .NET SDK to Native-AOT, we can eliminate most of this startup overhead, providing near-instantaneous command execution and dramatically improving the developer experience at scale. We can also showcase and encourage the adoption of Native AOT for CLI applications, and make the
dotnetCLI an example of a best-in-class .NET CLI application all-up.Scope and Approach
This Epic encompasses the technical work required to enable Native-AOT compilation of the .NET SDK, including infrastructure changes, library updates, and runtime integration modifications. The work will be executed in phases, starting with AOT compatibility enablement and culminating in a hybrid architecture where AOT handles command parsing while managed code handles complex operations.
Technical Implementation Strategy
Phase 1: Enable AOT Compatibility Analysis
Goal: Enable
IsAotCompatibleMSBuild property across the SDK repository to identify all AOT-incompatible code paths.<IsAotCompatible>true</IsAotCompatible>in Directory.Build.propsPhase 2: Resolve Core AOT Compatibility Issues
2.1 COM Interop Modernization
Problem: Current COM interop usage (e.g.,
DangerousFileDetector, VS workload manifest checking) uses reflection-based COM activation that's incompatible with AOT. There's a spike of what this might look like at #49669.Solution: Migrate to source-generated COM interop
2.2 Telemetry Infrastructure Modernization
Problem: ApplicationInsights libraries are not AOT-compatible and never will be.
Solution: Migrate to OpenTelemetry + Azure Monitor OTel exporter - @MiYanni and I have this mostly working at #49409.
Tracking issue: #49668
2.3 JSON Handling Modernization
Problem: Dynamic JSON handling throughout the codebase needs to use System.Text.Json source generators for AOT compatibility.
Solution: Implement source-generated JSON serialization
NuGet Libraries: NuGet/Home#14408
Templating libraries: the template engine is built on top of Newtonsoft.Json - we need to migrate it to System.Text.Json and enable source generation by consumers.
SDK JSON Usage:
ToolManifestEditor.csJSON handling to use source generatorsWorkloadManifestReader.csto use source-generated JSON2.4 MSBuild Evaluation Infrastructure Changes
Problem: MSBuild evaluation requires pluggable, AOT-compatible infrastructure.
Solution: Create AOT-friendly MSBuild integration points
Tracking issue: dotnet/msbuild#12141
SdkResolver Infrastructure:
Property Function Evaluation:
2.5 Roslyn dependencies
The file-based apps feature set uses Roslyn APIs to do lexing, but those aren't AOT'd today. There's a WIP for enabling trimming over at dotnet/roslyn#66519 that would be a prerequisite here.
Phase 3: Runtime Integration
3.1 Muxer Integration
Goal: Modify the .NET Runtime muxer to invoke the AOT-compiled SDK when available.
3.2 Hybrid Architecture Implementation
Goal: Create a hybrid model where AOT handles command parsing and common operations, with managed code for complex scenarios.
Command Parsing Migration:
Command Handler Strategy:
--version,--help,--info)dotnet.dllloading for managed handlersPhase 4: Incremental Command Migration
4.1 Pure-AOT Commands (Phase 4a)
Commands that do not use any of the above tech can be migrated to native handlers immediately.
dotnet --versiondotnet --infodotnet completedotnet completions4.3 Out-of-Process MSBuild Commands (Phase 4c)
Commands that perform MSBuild builds only (no evaluation) can be migrated to out-of-process MSBuild invocations immediately - note that file-based apps currently always must be handled by managed code, because they do build execution via the MSBuild API directly.
dotnet build4.2 Hybrid Commands (Phase 4b)
Commands that interact with NuGet/COM/MSBuild evaluation (which is most of them)
will need to wait until their associated blocker are migrated to AOT-compatible versions.
dotnet new(template parsing and instantiation)dotnet package add/remove(NuGet operations)dotent toolmanagement of all kindsdotnet workloadmanagement (install, update, list) of all kindsdotnet rundotnet testdotnet publish(uses one eval to determine if Release can be defaulted)dotnet packPartner Team Coordination
Dependencies on External Teams
.NET Runtime Team
NuGet Team
MSBuild Team
.NET Source-build Team
Success Metrics
Performance Targets
Quality Gates
Risks and Mitigations
Technical Risks
Delivery Risks