Skip to content

General nativeAOT support improvements#31228

Merged
PureWeen merged 4 commits intoinflight/currentfrom
doti/nativeaot-general-improvements
Aug 21, 2025
Merged

General nativeAOT support improvements#31228
PureWeen merged 4 commits intoinflight/currentfrom
doti/nativeaot-general-improvements

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 changes across several project and source files to improve compatibility with Ahead-of-Time (AOT) compilation and code trimming, as well as to support partial class declarations for future extensibility and code generation. The most important changes are grouped below:

  • Added the <IsAotCompatible>true</IsAotCompatible> property to multiple .csproj files (Core.csproj, Controls.Core.csproj, Controls.Xaml.csproj, Maps.csproj) to explicitly mark these projects as compatible with AOT compilation.
  • Refactored many Windows platform classes (e.g., ColorConverter, ContentPanel, LayoutPanel, MauiButton, MauiCancelButton, MauiHybridWebView, MauiWebView, MauiSlider, MauiStepper, PlatformTouchGraphicsView, etc.) to use the partial keyword, preparing them for code generation.

Issues Fixed

  • Many core projects are not marked IsAotCompatible, so no AOT incompatibility warnings are surfaced
  • Several important classes are missing partial declarations
  • Some projects require AllowUnsafeBlocks due to generated code that uses unsafe for trimming (e.g., LoopableCollectionView.cs, RelativeLayout.cs, …)

Part of #31227

Copilot AI review requested due to automatic review settings August 19, 2025 10:20
@morning4coffe-dev morning4coffe-dev requested a review from a team as a code owner August 19, 2025 10:20
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 pull request enhances .NET MAUI's compatibility with Ahead-of-Time (AOT) compilation and prepares the codebase for future code generation capabilities. The changes focus on marking projects as AOT-compatible and refactoring classes to support partial declarations.

  • Adds <IsAotCompatible>true</IsAotCompatible> property to core projects to enable AOT compatibility warnings
  • Converts Windows platform classes to use partial keyword for future extensibility
  • Enables AllowUnsafeBlocks for projects that implement generic WinRT interfaces requiring unsafe code

Reviewed Changes

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

Show a summary per file
File Description
src/Graphics/src/Graphics/Graphics.csproj Adds AOT compatibility flag
src/Graphics/src/Graphics.Win2D/Graphics.Win2D.csproj Adds conditional AOT compatibility flag for non-netstandard targets
src/Graphics/src/Graphics.Skia/Graphics.Skia.csproj Adds AOT compatibility flag
src/Core/src/Core.csproj Adds AOT compatibility and unsafe blocks support
src/Core/maps/src/Maps.csproj Adds AOT compatibility flag
src/Controls/src/Xaml/Controls.Xaml.csproj Adds AOT compatibility flag
src/Controls/src/Core/Controls.Core.csproj Adds AOT compatibility and unsafe blocks support
src/Core/src/Platform/Windows/*.cs Converts 18 Windows platform classes to partial declarations

</PropertyGroup>

<PropertyGroup>
<IsAotCompatible Condition="!$(TargetFramework.StartsWith('netstandard'))">true</IsAotCompatible>
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conditional logic for IsAotCompatible is inconsistent across project files. Graphics.csproj and Graphics.Skia.csproj place this property within a PropertyGroup that already has the netstandard condition, while Graphics.Win2D.csproj duplicates the condition on the property itself. For consistency, either move this property into the existing conditional PropertyGroup or apply the same pattern across all Graphics projects.

Copilot uses AI. Check for mistakes.
@morning4coffe-dev morning4coffe-dev changed the title Doti/nativeaot general improvements General nativeAOT support improvements Aug 19, 2025
@baaaaif
Copy link

baaaaif commented Aug 19, 2025

Just a note:
Microsoft is working on making partial for types and AllowUnsafeBlocks no longer necessary
https://github.com/microsoft/CsWinRT/blob/user/sergiopedri/cswinrt3.0-docs/docs/cswinrt3.0-spec.md

Copy link
Member

@simonrozsival simonrozsival left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@PureWeen PureWeen changed the base branch from main to inflight/current August 21, 2025 10:35
@PureWeen PureWeen merged commit e74ad78 into inflight/current Aug 21, 2025
127 of 129 checks passed
@PureWeen PureWeen deleted the doti/nativeaot-general-improvements branch August 21, 2025 10:35
github-actions bot pushed a commit that referenced this pull request Aug 22, 2025
* Mark projects IsAotCompatible and AllowUnsafeBlocks

* Make Windows Platform classes partial

* Mark PlatformGraphicsView partial

* Mark SkiaGraphicsView partial
jfversluis pushed a commit that referenced this pull request Aug 25, 2025
* Mark projects IsAotCompatible and AllowUnsafeBlocks

* Make Windows Platform classes partial

* Mark PlatformGraphicsView partial

* Mark SkiaGraphicsView partial
github-actions bot pushed a commit that referenced this pull request Sep 4, 2025
* Mark projects IsAotCompatible and AllowUnsafeBlocks

* Make Windows Platform classes partial

* Mark PlatformGraphicsView partial

* Mark SkiaGraphicsView partial
github-actions bot pushed a commit that referenced this pull request Sep 5, 2025
* Mark projects IsAotCompatible and AllowUnsafeBlocks

* Make Windows Platform classes partial

* Mark PlatformGraphicsView partial

* Mark SkiaGraphicsView partial
@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 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.

4 participants