WindowsAppSDK icon indicating copy to clipboard operation
WindowsAppSDK copied to clipboard

MAUI Blazor Windows App does not work with Native AOT

Open strich opened this issue 1 year ago • 3 comments

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

strich avatar Sep 29 '23 00:09 strich

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.

DarranRowe avatar Sep 29 '23 20:09 DarranRowe

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

manodasanW avatar Sep 30 '23 00:09 manodasanW

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.

strich avatar Sep 30 '23 02:09 strich