Skip to content

[Windows] Improve NativeAOT support #31227

@morning4coffe-dev

Description

@morning4coffe-dev

NativeAOT is publishing option in .NET and WinAppSDK 1.6 that introduced official support for AOT on Windows. However, MAUI’s Windows target currently requires a lot of manual adjustments to build and run successfully under NativeAOT.

This issue proposes improving out-of-the-box support so that enabling PublishAot=true works without extra steps as current gaps lead to build errors, analyzer warnings, and runtime crashes out of the box (unless developers manually tweak/trim project files and MAUI package).

Current State / Findings

Platform/Packaging

  • On .NET 10 Preview 5/6, NativeAOT only worked with packaged apps (based on observations/discussions)
  • With MAUI AOT, packaging + signing must be performed after publish
    • In my tests, I included CreateMsixAfterPublish
    • Open question: Can/should we standardize this and enable it as part of publish if it still has issues?

Build Configuration / Properties

  • Runtime Identifier
    RuntimeIdentifierOverride must be set (e.g. p:RuntimeIdentifierOverride=win10-x64)

Errors observed:

  • RuntimeIdentifier 'win10-x64' is not recognized
  • Ahead-of-time compilation is not supported for the target runtime identifier 'win10-x64'

PRI Resource Generation

  • Publishing sometimes fails due to a PRI resource generation error
  • Workaround: set EmbedXbfInPri=false.

Symbols Included in Package

  • Debug symbols are getting included, nearly doubling package size
  • Workaround: disable symbols on user project to reduce size:
<DebugSymbols>false</DebugSymbols>
<DebugType>None</DebugType>

Observed MAUI Codebase Gaps

Tests & Documentation

  • Add Windows to nativeAOT template integration test #31250 Integration Tests: Add coverage in AOTTemplateTest to validate packaged publish + run for Windows
  • Docs: Update documentation with:
    • Remaining manual steps that cannot be moved into .targets
    • Known issues and mitigations
    • Common pitfalls (RIDs, PRI generation, symbol size) and recommended defaults

Benefits

  • Simplifies developer experience: no manual csproj edits apart PublishAot or obscure analyzer fixes
  • Aligns MAUI with .NET’s AOT strategy and WinAppSDK’s capabilities
  • Improves startup performance and drastically reduces app size on Windows
  • In my simple sample app I was able to achieve a reduction from 89.5 MiB to 37 MiB with a noticeable startup time boost

Info

  • Tested on my side with .NET: 10.0.100-preview.6
  • Microsoft.WindowsAppSDK: 1.7.250606001

References

Metadata

Metadata

Labels

perf/generalThe issue affects performance (runtime speed, memory usage, startup time, etc.) (sub: perf)t/enhancement ☀️New feature or request

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions