microsoft / WindowsAppSDK

The Windows App SDK empowers all Windows desktop apps with modern Windows UI, APIs, and platform features, including back-compat support, shipped via NuGet.
https://docs.microsoft.com/windows/apps/windows-app-sdk/
MIT License
3.85k stars 322 forks source link

MAUI Blazor Windows App does not work with Native AOT #3887

Open strich opened 1 year ago

strich commented 1 year ago

Describe the bug

This is a cross-post bug from the MAUI project (https://github.com/dotnet/maui/issues/17713) at the request of their developers.

I am currently developing an app with Avalonia on .NET 7 and I was curious to see if I could move to MAUI Blazor as it'd improve my productivity. I do not plan to release the app on anything but desktop platforms, and even then I may keep it to Windows.

It is important to me to have Native AOT. I got this working with Avalonia by adding the following to my csproj:

<SelfContained>false</SelfContained>
<PublishSingleFile>false</PublishSingleFile>
<PublishReadyToRun>false</PublishReadyToRun>
<TrimMode>partial</TrimMode>
<PublishAot>true</PublishAot>
<OptimizationPreference>Speed</OptimizationPreference>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>

I installed the latest MAUI and created the default MAUI Blazor project in VS. I've attempted to apply the same or similar csproj settings, starting with just <PublishAot> and each step of the way the commandline publish has spit out errors. I cannot currently get it to work.

How can I get the default start up project to publish to native AOT?

Steps to reproduce the bug

Create a new .NET Blazor MAUI App in VS.
Remove all platforms from the csproj except Windows to simply things.
Try to get it to compile to AOT.

Expected behavior

No response

Screenshots

No response

NuGet package version

None

Packaging type

Unpackaged

Windows version

Windows 11 version 22H2 (22621, 2022 Update)

IDE

Visual Studio 2022-preview, Visual Studio 2022

Additional context

No response

DarranRowe commented 1 year ago

IIRC, the biggest thing getting in the way of the Windows App SDK being usable for Native AOT is Cs/WinRT. The .NET projections are created using Cs/WinRT. What's more, since you mentioned .NET 7, the documentation states that Native AOT is targeted at console type applications in .NET 7. I would suspect that Native AOT will not be fully supported until .NET 8 is released and Cs/WinRT declares full compatibility.

manodasanW commented 1 year ago

You can find my recent update on AOT status here: https://github.com/microsoft/WindowsAppSDK/discussions/3856#discussioncomment-7017551

strich commented 1 year ago

IIRC, the biggest thing getting in the way of the Windows App SDK being usable for Native AOT is Cs/WinRT. The .NET projections are created using Cs/WinRT. What's more, since you mentioned .NET 7, the documentation states that Native AOT is targeted at console type applications in .NET 7. I would suspect that Native AOT will not be fully supported until .NET 8 is released and Cs/WinRT declares full compatibility.

Note that whilst I initially tried it on net 7 i since moved to NET 8 RC1 and had the same issue.