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

Publish Unpackaged Apps Error(Project Reference MAUI Library ) #9064

Closed
Tracked by #10564
bflyman opened this issue Jul 29, 2022 · 9 comments
Closed
Tracked by #10564

Publish Unpackaged Apps Error(Project Reference MAUI Library ) #9064

bflyman opened this issue Jul 29, 2022 · 9 comments
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) delighter partner/winui WinUI / Project Reunion platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working

Comments

@bflyman
Copy link

bflyman commented Jul 29, 2022

Description

I created a MAUI APP using the following command and the resulting EXE works just fine.
dotnet publish -f net6.0-windows10.0.22621.0 -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true -p:GenerateAppxPackageOnBuild=false
But when I created a MAUI Libaray and referenced it in my APP project, the above publish command failed

The main error messages are:
Could not find a part of the path 'J:\TestProject\MauiLib2\obj\Debug\net6.0-windows10.0.19041.0\MsixContent\AppxManifest.xml'. [J:\TestProject\MauiLib2\MauiLib2.csproj]

Steps to Reproduce

1.create Maui APP
2.create Maui Lib
3. APP Project Reference Lib
4. App MainPage.cs Add a little code
Lib.Class1 c = new Lib.Class1();
builder.Services.AddSingleton(c);

PS:The generation succeeds without adding code.

Version with bug

6.0.400

Last version that worked well

6.0.400

Affected platforms

Windows

Affected platform versions

Windows

Did you find any workaround?

pack Maui libaray and add package the libaray

Relevant log output

 C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018: “GenerateWinRTManifestFromAppx”任务意外失败。 [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018: System.IO.DirectoryNotFoundException: Could not find a part of the path 'J:\TestProject\MauiLib2\obj\Debug\net6.0-windows10.0.19041.0\MsixContent\AppxManifest.xml'. [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.IO.Strategies.OSFileStreamStrategy..ctor(String path, FileMode mode, FileAccess access, FileShare share, FileOptions options, Int64 preallocationSize) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.IO.Strategies.FileStreamHelpers.ChooseStrategy(FileStream fileStream, String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, Int64 preallocationSize) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlTextReaderImpl.OpenUrl() [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlTextReaderImpl.Read() [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlDocument.Load(XmlReader reader) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at System.Xml.XmlDocument.Load(String filename) [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at InlineCode.GenerateWinRTManifestFromAppx.Execute() [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [J:\TestProject\MauiLib2\MauiLib2.csproj]
C:\Users\bflyman\.nuget\packages\microsoft.windowsappsdk\1.1.1\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(239,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [J:\TestProject\MauiLib2\MauiLib2.csproj]

VS bug #1759006

@bflyman bflyman added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Jul 29, 2022
@Eilon Eilon added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Aug 1, 2022
@jfversluis jfversluis removed the s/needs-verification Indicates that this issue needs initial verification before further triage will happen label Aug 24, 2022
@samhouts samhouts added the partner/winui WinUI / Project Reunion label Mar 3, 2023
@wulf11
Copy link

wulf11 commented Jun 8, 2023

Can confirm the problems. Updated my Visual Studio 2022 to Version 17.6.2 and now my .NET 7 MAUI Blazor application can't publish with -p:WindowsAppSDKSelfContained=true. The problems occus when a class library project is added and referenced.

@wulf11
Copy link

wulf11 commented Aug 21, 2023

Hey guys I may found a workaround that I want to share with you.
It seems that the WindowsAppSDKSelfContained requires an "AppxManifest.xml" from a folder called MsixContent. These files are not created for the MAUI library projects for some reason. I am not quite sure which side is responsible for this (team MAUI or team WindowsAppSDK). But here is a quick guide how I could resolve the issues (for several projects I have):

  1. clean up the solution (delete bin and obj folder of each if necessary)
  2. rebuild solution
  3. execute build via Powershell

dotnet build

  1. dotnet publish -c Release -f net7.0-windows10.0.19041.0 -p:WindowsPackageType=None -p:SelfContained=true
  2. navigate to the start project (main project) with the file explorer:

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

  1. copy AppxManifest.xml

  2. navigate with the file explorer to the library project (MAUI library or side project)

/obj/Release/net7.0-windowsxxxxx/win10-x64/

  1. create here the missing folder MsixContent
  2. insert the AppxManifest.xml
  3. dotnet publish -c Release -f net7.0-windows10.0.19041.0 -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true

Well you got the idea..you need to provide an AppxManifest.xml. Not quite sure if its a problem if I just copy it from the "main" project to the other solutions, but it worked for me so far.

I hope that may give some hints for the devs to find the bug.

@mattleibow
Copy link
Member

I believe this is fixed for apps. But the real issue is that publishing only works if you pass the project and not a solution. It will try publish the library project as an app, which is not supported.

This is an old issue, but did you manage to publish the app?

@mattleibow mattleibow added the s/needs-info Issue needs more info from the author label Oct 26, 2023
@ghost
Copy link

ghost commented Oct 26, 2023

Hi @bflyman. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Oct 30, 2023
@ghost
Copy link

ghost commented Oct 30, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@wulf11
Copy link

wulf11 commented Oct 31, 2023

Lets say I have a solution that contains a "main" project and a library project. It would fail in both scenarios when the main project references the library project. The error occured randomely, but I could always resolve it with a copy of AppxManifest.xml.

So yes app publishing works, but only if you know what you are doing.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author s/no-recent-activity Issue has had no recent activity labels Oct 31, 2023
@mattleibow
Copy link
Member

mattleibow commented Nov 1, 2023

I am pretty sure there is an authoring issue in the WinUI targets. If you set the <WindowsAppSDKSelfContained> property in the csproj then for some reason the library works again.

I think this is the same issue where setting the RuntimeIdentifier on the CLI tries to make library projects into apps. microsoft/WindowsAppSDK#3337

To work around this I have to add this to csprojs that want a RID-specific build:

<PropertyGroup Condition="'$(RuntimeIdentifierOverride)' != ''">
	<RuntimeIdentifier>$(RuntimeIdentifierOverride)</RuntimeIdentifier>
</PropertyGroup>

This could then be replicated and used to set the property on the CLI:

<PropertyGroup Condition="'$(WindowsAppSDKSelfContainedOverride)' != ''">
	<WindowsAppSDKSelfContained>$(WindowsAppSDKSelfContainedOverride)</WindowsAppSDKSelfContained>
</PropertyGroup>

It is unfortunate, but there seems to be an ordering issue where setting properties trigger targets to do things even when they are not relevant for the project.

I logged another issue on this as well: microsoft/WindowsAppSDK#4008

So, as a workaround for now, you can:

  • add the WindowsAppSDKSelfContained property to the csproj
  • add the snippet above and set the ovveride on the CLI
  • use net8 which automatically sets the self contained to true and thus you do not have to

@mattleibow mattleibow added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Nov 3, 2023
@ghost
Copy link

ghost commented Nov 3, 2023

Hi @bflyman. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@ghost ghost added the s/no-recent-activity Issue has had no recent activity label Nov 7, 2023
@ghost
Copy link

ghost commented Nov 7, 2023

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@ghost ghost closed this as completed Nov 10, 2023
@ghost ghost removed the s/no-recent-activity Issue has had no recent activity label Nov 30, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) delighter partner/winui WinUI / Project Reunion platform/windows 🪟 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants