Unable to publish unpackaged WinUI3 application
Describe the bug
Attempting to publish an unpackaged MAUI application with 1.6 WASDK and .NET 9 results in the following obscure error message:
WindowsAppSDKSelfContained requires a supported Windows architecture.
The command I'm using to publish is linked below.
dotnet publish myapp.csproj -c Release -f net9.0-windows10.0.19041.0 -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true -p:RuntimeIdentifierOverride=win-x64
Steps to reproduce the bug
I can't reproduce this out of the box, but I have no idea where to look at building a repro for this.
Expected behavior
Compiles
Screenshots
No response
NuGet package version
None
Packaging type
Unpackaged
Windows version
No response
IDE
Other
Additional context
Windows App SDK version: 1.6.240923002
To confirm, does your project set RuntimeIdentifier based on RuntimeIdentifierOverride?
Specifying an explicit RID with -p:RuntimeIdentifier=win-x64 gets me a bit further with new errors.
Unable to find package Microsoft.NETCore.App.Runtime.Mono.win-x64 with version (= 9.0.0)
- Found 102 version(s) in nuget.org [ Nearest version: 9.0.0-preview.7.24405.7 ]
- Found 102 version(s) in NuGet official package source [ Nearest version: 9.0.0-preview.7.24405.7 ]
- Found 0 version(s) in Microsoft Visual Studio Offline Packages
- Found 0 version(s) in C:\Program Files\dotnet\library-packs
For me it does work to publish an unpackaged WinUI3 app only when -p:WindowsPackageType=None is not set.
My .csproj looks like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net9.0-windows10.0.19041.0</TargetFramework>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x64</Platforms>
<RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
<ImplicitUsings>true</ImplicitUsings>
<Nullable>enable</Nullable>
<UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
<SelfContained>true</SelfContained>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.241114003" />
</ItemGroup>
</Project>
With this i can publish my app with simply doing dotnet publish .\FooApp.csproj -r win-x64 -o publish.
@daltzctr For your Unable to find package Microsoft.NETCore.App.Runtime.Mono.win-x64 with version (= 9.0.0) error. The MonoVM desktop packages are not available anymore starting with .NET 9 Preview 7: https://learn.microsoft.com/en-us/dotnet/core/compatibility/deployment/9.0/monovm-packages
FWIW, this actually happens for trying to build unpackaged MAUI apps targeting Windows as well.
Using the command from the docs:
dotnet publish -f net9.0-windows10.0.19041.0 -p:RuntimeIdentifierOverride=win-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
Core net9.0-windows10.0.19041.0 failed with 1 error(s) (0.1s)
C:\Users\subka\.nuget\packages\microsoft.windowsappsdk\1.6.241114003\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(75,9): error : WindowsAppSDKSelfContained requires a supported Windows architecture.
Build failed with 1 error(s) in 0.5s
I modified the RID to win-x64 based on the .NET 8 changes.
If I use -r win-x64 I get the Mono error:
dotnet publish -f net9.0-windows10.0.19041.0 -r win-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
App.csproj : error NU1102:
Unable to find package Microsoft.NETCore.App.Runtime.Mono.win-x64 with version (= 9.0.5)
- Found 107 version(s) in nuget.org [ Nearest version: 9.0.0-preview.7.24405.7 ]
Workaround:
If I leave off -p:WindowsAppSDKSelfContained=true then the first command will work but this is obviously less than ideal.
Edit:
Oh 🤦 I just noticed the Core reference there. That's my .NET MAUI class library project. If I add the RuntimeIdentifierOverride property group in that project as well, the first command "works" but I get another error:
App net9.0-windows10.0.19041.0 failed with 1 error(s) (2.4s) → bin\Release\net9.0-windows10.0.19041.0\win-x64\App.dll
C:\Program Files\dotnet\sdk\9.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.ConflictResolution.targets(112,5): error NETSDK1152: Found multiple publish output files with the same relative path:
This may be a separate issue for .NET MAUI.
After some offline discussion with some Microsoft staff and binlogs, I learned that my problem was
- MAUI
- Multi project solution where MAUI app depended on non-MAUI included projects (.NET Standard)
Something was setting the project to use the mono runtime no matter what. My workaround is to set the UseMonoRuntime property to false on Windows platform. (Actual name of the property may be different. Going from memory.)