Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing MSBuild properties on the CLI throws errors #4008

Closed
mattleibow opened this issue Nov 30, 2023 · 6 comments
Closed

Passing MSBuild properties on the CLI throws errors #4008

mattleibow opened this issue Nov 30, 2023 · 6 comments
Labels
maui-7.x Bugs targeted for maui-7.x

Comments

@mattleibow
Copy link

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: #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: #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
Copy link

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
Copy link

MattePozzy commented Jan 8, 2024

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
Copy link

anpin commented May 6, 2024

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

@LucHeart
Copy link

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
Copy link

wulf11 commented May 23, 2024

@anpin only workaround I know is described in dotnet/maui#9064 (comment)

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.

@evelynwu-msft
Copy link
Contributor

@mattleibow The error message is correct. Using the -p switch results in the setting of a global property. The subsequent errors are basically cascading from this because WindowsAppSDKSelfContainer simply isn't applicable to class libraries. Your workaround inadvertently avoids this by only setting the WindowsAppSDKSelfContained property for the one project that it applies to.

I'm going to close this issue because ultimately it's the result of downstream consequences of attempting to workaround #3337. For everybody else in this thread, unless your scenario is exactly the same as that described by Mathew in #3337 and the information I posted in #3337 (comment) does not resolve the issues you are encountering please open a new issue so that it can be tracked separately instead of getting lost amongst the comments of this unrelated issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maui-7.x Bugs targeted for maui-7.x
Projects
None yet
Development

No branches or pull requests

7 participants