General nativeAOT support improvements#31228
Conversation
There was a problem hiding this comment.
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
partialkeyword for future extensibility - Enables
AllowUnsafeBlocksfor 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> |
There was a problem hiding this comment.
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.
|
Just a note: |
* Mark projects IsAotCompatible and AllowUnsafeBlocks * Make Windows Platform classes partial * Mark PlatformGraphicsView partial * Mark SkiaGraphicsView partial
* Mark projects IsAotCompatible and AllowUnsafeBlocks * Make Windows Platform classes partial * Mark PlatformGraphicsView partial * Mark SkiaGraphicsView partial
* Mark projects IsAotCompatible and AllowUnsafeBlocks * Make Windows Platform classes partial * Mark PlatformGraphicsView partial * Mark SkiaGraphicsView partial
* Mark projects IsAotCompatible and AllowUnsafeBlocks * Make Windows Platform classes partial * Mark PlatformGraphicsView partial * Mark SkiaGraphicsView partial
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:
<IsAotCompatible>true</IsAotCompatible>property to multiple.csprojfiles (Core.csproj,Controls.Core.csproj,Controls.Xaml.csproj,Maps.csproj) to explicitly mark these projects as compatible with AOT compilation.ColorConverter,ContentPanel,LayoutPanel,MauiButton,MauiCancelButton,MauiHybridWebView,MauiWebView,MauiSlider,MauiStepper,PlatformTouchGraphicsView, etc.) to use thepartialkeyword, preparing them for code generation.Issues Fixed
Part of #31227