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.72k stars 308 forks source link

Passing MSBuild properties on the CLI throws errors #4008

Open mattleibow opened 7 months ago

mattleibow commented 7 months ago

Describe the bug

I have a maui app which has a maui library. When I publish the app:

dotnet publish -f net8.0-windows10.0.19041.0 -c Release -r win10-x64 -p:WindowsAppSDKSelfContained=true -p:SelfContained=true

I get this error: https://github.com/microsoft/WindowsAppSDK/issues/3337

I fixed this by adding the RID to the csproj:

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(RuntimeIdentifierOverride)' != ''">
    <RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
</PropertyGroup>

Now I can pass -p:RuntimeIdentifierOverride=win10-x64 instead:

dotnet publish -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsAppSDKSelfContained=true -p:SelfContained=true

I still get this error:

C:\Users\maleib\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(36,5): error : The platform 'AnyCPU' is not supported for Self Contained mode.

I partially worked around this by doing this: https://github.com/microsoft/WindowsAppSDK/issues/2684 and adding this to my DirectoryBuild.targets:

<Project>
    <Target Name="WindowsAppSDKSelfContainedVerifyConfiguration">
    </Target>
</Project>

Now I get another error:

 error MSB4018: The "GenerateAppManifestFromAppx" task failed unexpectedly. 
 error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Projects\Testing\MauiApp193\MauiLib1\obj\Release\net8.0-windows10.0.19041.0\MsixContent\AppxManifest.xml'.
 error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options)
 error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) 
 error MSB4018:    at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) 
 error MSB4018:    at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable`1 unixCreateMode) 
 error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) 
 error MSB4018:    at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy) 
 error MSB4018:    at System.Xml.XmlTextReaderImpl.OpenUrl() 
 error MSB4018:    at System.Xml.XmlTextReaderImpl.Read() 
 error MSB4018:    at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) 
 error MSB4018:    at System.Xml.XmlDocument.Load(XmlReader reader)
 error MSB4018:    at System.Xml.XmlDocument.Load(String filename) 
 error MSB4018:    at InlineCode.GenerateAppManifestFromAppx.Execute() 
 error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 
 error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) 

I can work around this by adding this to my csproj:

<WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained>

I have worked around this in .NET maui by making all unpackaged apps be WindowsAppSDKSelfContained by default, but MSIX apps still need to do this sometimes.

Steps to reproduce the bug

  1. Download MauiAppTest.zip
  2. Publish the app:
    dotnet publish -f net8.0-windows10.0.19041.0 -c Release -r win10-x64 -p:WindowsAppSDKSelfContained=true -p:SelfContained=true

Expected behavior

Publish works

Screenshots

No response

NuGet package version

Windows App SDK 1.4.3: 1.4.231115000

Packaging type

Packaged (MSIX), Unpackaged

Windows version

No response

IDE

Other

Additional context

No response

BurkusCat commented 5 months ago

I'm trying to publish a Packaged app with WindowsAppSDKSelfContained=true to avoid users needing to install the .NET 8 runtime separately. I've tried all the steps in your post @mattleibow to workaround this issue but I actually end up with this result:

C:\Users\runneradmin\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.Build.Msix.Packaging.targets(354,5): warning : Path to `mspdbcmf.exe` could not be found. A symbols package will not be generated. Review https://aka.ms/windowsappsdkdocs and ensure that all prerequisites for Windows App SDK development have been installed. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]
MakeAppx : error : Manifest validation error: Line 29, Column 27, Reason: The file name "Catlists.exe" declared for element "*[local-name()='Applications']/*[local-name()='Application']" doesn't exist in the package. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]
MakeAppx : error : Package creation failed. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]
MakeAppx : error : 0x[80](https://github.com/BurkusCat/Catlists/actions/runs/7439263733/job/20238950717#step:9:81)080204 - The specified package format is not valid: The package manifest is not valid. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]
Error: Process completed with exit code 1.
MattePozzy commented 5 months ago

Hi, I have a net 8 MAUI app that include a cspoj of a library.

I have tried to add to both project (I also have tried a mix of options)

<PropertyGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows' and '$(RuntimeIdentifierOverride)' != ''">
    <RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
</PropertyGroup>

<Target Name="WindowsAppSDKSelfContainedVerifyConfiguration"></Target>

<WindowsPackageType Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">None</WindowsPackageType>
<WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained>
<PublishSingleFile>True</PublishSingleFile>
<SelfContained>True</SelfContained>

to try to create a single EXE of my application.

I used this command: dotnet publish -f:net8.0-windows10.0.19041.0 -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true -p:RuntimeIdentifierOvveride=win-x64

but I always get this error (LibMobile is the library project): C:\Users\pozzy\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: The "GenerateAppManifestFromAppx" task failed unexpectedly. [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\pozzy\Documents\Progetti\LibMobile\obj\Release\net8.0-windows10.0.19041.0\MsixContent\AppxManifest.xml'. [C:\Users\pozzy\Doc
uments\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.cs
proj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode) [C:\Users\p
ozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode) [C:\Users\pozzy
\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.IO.Strategies.FileStreamHelpers.ChooseStrategyCore(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize, Nullable1 unixCreateMode) [C:\U
sers\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windo
ws10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.Xml.XmlTextReaderImpl.OpenUrl() [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.Xml.XmlTextReaderImpl.Read() [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.Xml.XmlDocument.Load(XmlReader reader) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at System.Xml.XmlDocument.Load(String filename) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at InlineCode.GenerateAppManifestFromAppx.Execute() [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0
]
C:\Users\pozzy.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToEx
ecuteTask) [C:\Users\pozzy\Documents\Progetti\LibMobile\LibMobile.csproj::TargetFramework=net8.0-windows10.0.19041.0] `

anpin commented 1 month ago

Setting <WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained> still fails with error MSB4018: The "GenerateAppManifestFromAppx" task failed unexpectedly.. @mattleibow have you found a workaround?

LucHeart commented 1 month ago

This also happens when setting Platform to anything other than x64 for me... I need multi platform support on this here, otherwise this is a mess to work with...

wulf11 commented 1 month ago

@anpin only workaround I know is described in https://github.com/dotnet/maui/issues/9064#issuecomment-1685883983

I had this problem also in .NET 7.. Somehow the AppxManifest.xml file won't be generated if you use the -p:WindowsAppSDKSelfContained=true flag in a multi-project solution. The workaround is to publish without the parameter first, this will create the File in your main project under

/obj/Release/net8.0-windowsxxxxx/win10-x64/MsixContent/

Then you need to manually copy it into the other projects under /obj/Release/net8.0-windowsxxxxx/win10-x64/ in an "MsixContent" folder (you have to create it). Then run with your full publish command using the

-p:WindowsAppSDKSelfContained=true

I really don't know whats causing this..but the WindowsAppSDKSelfContained param surely is somehow guilty and the fact that it only occurs only multi-project solutions.