Skip to content

Conversation

@morning4coffe-dev
Copy link
Contributor

Note

Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!

Description of Change

This pull request introduces several targeted improvements to support Native AOT publishing and to address issues specific to WinUI and Windows platform builds. The main focus is on increasing stability for Native AOT scenarios, avoiding runtime crashes, and improving build configuration for Windows projects. Inlcuding added DynamicDependency attributes to MauiNavigationView.cs to ensure required types and members are preserved during trimming for Native AOT scenarios.

Issues Fixed

Improving MAUI WinUI nativeAOT stability.

Part of #31227

@morning4coffe-dev morning4coffe-dev marked this pull request as ready for review September 1, 2025 14:40
Copilot AI review requested due to automatic review settings September 1, 2025 14:40
@morning4coffe-dev morning4coffe-dev requested a review from a team as a code owner September 1, 2025 14:40
Copy link
Contributor

Copilot AI left a comment

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 introduces several stability improvements for Native AOT publishing scenarios on Windows platforms. The changes focus on avoiding runtime crashes and improving build configuration by adding dependency attributes for trimming preservation and implementing workarounds for known AOT issues.

  • Adds DynamicDependency attributes to preserve required types during Native AOT trimming
  • Implements conditional compilation to avoid Win2D crashes under Native AOT
  • Improves Shell navigation timing to prevent WinUI template application failures

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Core/src/Platform/Windows/MauiNavigationView.cs Adds DynamicDependency attributes to preserve WinUI control types during AOT trimming
src/Core/src/Fonts/FontManager.Windows.cs Conditionally disables Win2D font lookup under Native AOT to prevent crashes
src/Controls/src/Xaml/Controls.Xaml.csproj Disables PRI generation for Windows to avoid conflicts with Core project
src/Controls/src/Core/Handlers/Shell/ShellItemHandler.Windows.cs Delays MenuItemsSource assignment until NavigationView is loaded to prevent AOT crashes
src/Controls/src/Build.Tasks/nuget/buildTransitive/netstandard2.0/Microsoft.Maui.Controls.targets Sets default build properties for Windows Native AOT publishing
Comments suppressed due to low confidence (1)

src/Core/src/Fonts/FontManager.Windows.cs:168

  • The conditional compilation symbol USE_NATIVE_AOT appears to be a custom symbol not defined in the standard .NET build system. Consider using the standard NATIVE_AOT symbol that is automatically defined by the .NET SDK when PublishAot=true, or ensure this custom symbol is properly defined in the project configuration.
#if USE_NATIVE_AOT

@PureWeen PureWeen changed the base branch from main to inflight/candidate September 18, 2025 20:21
@PureWeen PureWeen merged commit 780feec into inflight/candidate Sep 18, 2025
129 checks passed
@PureWeen PureWeen deleted the doti/nativeaot-code-changes branch September 18, 2025 20:21
github-actions bot pushed a commit that referenced this pull request Sep 18, 2025
* Misc nativeAOT Windows compatibility fixes

* Adjust conditional for font retrieval in FontManager.Windows

* Revert ShellItemHandler changes and  update MauiNavigationView with dynamic dependencies
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
* Misc nativeAOT Windows compatibility fixes

* Adjust conditional for font retrieval in FontManager.Windows

* Revert ShellItemHandler changes and  update MauiNavigationView with dynamic dependencies
github-actions bot pushed a commit that referenced this pull request Sep 23, 2025
* Misc nativeAOT Windows compatibility fixes

* Adjust conditional for font retrieval in FontManager.Windows

* Revert ShellItemHandler changes and  update MauiNavigationView with dynamic dependencies
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants