unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
9.03k stars 733 forks source link

Can't set `<PublishAot>` in the .csproj file with multiple `TargetFrameworks` #18838

Closed felixf4xu closed 2 days ago

felixf4xu commented 2 days ago

Current behavior

In a Uno project with multiple TargetFrameworks, I can't set <PublishAot> to enable AOT, the error message is:

error NETSDK1203: Ahead-of-time compilation is not supported for the target runtime identifier 'browser-wasm'.

Expected behavior

Standard AOT configurations should be able to use in Uno project file, like:

      <PublishTrimmed>true</PublishTrimmed>
      <PublishAot>true</PublishAot>
      <PublishSingleFile>true</PublishSingleFile>

How to reproduce it (as minimally and precisely as possible)

A project file with multiple TargetFrameworks:

<TargetFrameworks>net9.0-android;net9.0-ios;net9.0-maccatalyst;net9.0-windows10.0.26100;net9.0-browserwasm;net9.0-desktop</TargetFrameworks>

Add these configurations into the .csproj file

      <PublishTrimmed>true</PublishTrimmed>
      <PublishAot>true</PublishAot>
      <PublishSingleFile>true</PublishSingleFile>

then run dotnet publish -f net9.0-desktop

Workaround

I have to remove net9.0-browserwasm from the <TargetFrameworks> temporarily to run:

dotnet publish -f net9.0-desktop

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

Same error on Ubuntu if only dotnet publish -f net9.0-desktop is used (no VS publish)