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

Users require .NET 8 to be downloaded separately to run WinUI app #19763

Closed
BurkusCat opened this issue Jan 8, 2024 · 16 comments
Closed

Users require .NET 8 to be downloaded separately to run WinUI app #19763

BurkusCat opened this issue Jan 8, 2024 · 16 comments
Labels
area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) platform/windows 🪟 s/needs-attention Issue has more information and needs another look t/bug Something isn't working

Comments

@BurkusCat
Copy link
Contributor

BurkusCat commented Jan 8, 2024

Description

When building a packaged WinUI app on a pipeline, the artifacts including with Windows runtime dependency are given to the user/customer. The user/customer runs the install PowerShell scripts which I think should install dependencies, however, when they try to launch the app, they are prompted to install the .NET 8 runtime.

Sideloading:
image

Directly from Microsoft Store:
image

After installing the runtime, the app does start. But this is a very poor user experience and won't be acceptable for the Microsoft Store. My other attempts produced builds that also required .NET8/the app failed to start.

Steps to Reproduce

Attempt 1 (packaged, mostly defaults and where I first encountered the issue):
dotnet publish -f net8.0-windows10.0.19041.0 -c:Release -p:RuntimeIdentifierOverride=win10-x64 -p:PackageCertificateThumbprint=${{ secrets.WIN_CERT_THUMBPRINT }}

App requires .NET8 runtime but it does start successfully.

Generally, I had been following instructions/guidance from here: https://learn.microsoft.com/en-us/dotnet/maui/windows/deployment/publish-cli?view=net-maui-8.0

Attempt 2 (Packaged self-contained app):
dotnet publish -f net8.0-windows10.0.19041.0 -c:Release -p:RuntimeIdentifierOverride=win-x64 -p:Platform=x64 -p:PackageCertificateThumbprint=${{ secrets.WIN_CERT_THUMBPRINT }} -p:WindowsAppSDKSelfContained=true

Including all the workarounds described in: microsoft/WindowsAppSDK#4008

This produces a 49.2mb file (it actually got smaller than my previous builds of 104.4mb without WindowsAppSDKSelfContained). The same issue occurs and the app also crashes on startup.

Crash log from app center:

ctor
System.Runtime.InteropServices.COMException: Class not registered (0x80040154 (REGDB_E_CLASSNOTREG))

System.Runtime.InteropServices
Marshal.ThrowExceptionForHR (Int32 errorCode)
WinRT.BaseActivationFactory
WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
WinRT.ActivationFactory`1
WinRT.ActivationFactory`1..cctor()
WinRT
ActivationFactory`1.ActivateInstance[I] ()
Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl
Microsoft.Graphics.Canvas.UI.Xaml.CanvasControl..ctor()
Microsoft.Maui.Graphics.Win2D
W2DGraphicsView.UserControl_Loaded (Object sender, RoutedEventArgs e)
ABI.Microsoft.UI.Xaml
RoutedEventHandler.Do_Abi_Invoke (IntPtr thisPtr, IntPtr sender, IntPtr e)
WinRT
ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0 (Int32 hr)
WinRT
ExceptionHelpers.ThrowExceptionForHR (Int32 hr)
ABI.Windows.ApplicationModel.Core
IUnhandledErrorMethods.Propagate (IObjectReference _obj)
Windows.ApplicationModel.Core
UnhandledError.Propagate ()
Microsoft.AppCenter.Utils
ApplicationLifecycleHelperWinUI.<ctor>b__0_3 (Object sender, UnhandledErrorDetectedEventArgs eventArgs)

Generally, I had been following instructions/guidance from here: https://learn.microsoft.com/en-us/dotnet/maui/windows/deployment/publish-unpackaged-cli?view=net-maui-8.0

Attempt 3 (Unpackaged self-contained app):
Update the csproj to have the below but kept all the changes made in Attempt 1.

    <WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained>
    <WindowsPackageType>None</WindowsPackageType>
    <PublishSingleFile>true</PublishSingleFile>

The folder full of files is roughly about 230mb in size (Which sounds promising). Its an unpackaged app but I think this will be fine for me as I do need to upload this to the Steam store. Strangely, the app isn't a single file?

Folder of files

Link to public reproduction project repository

No response

Version with bug

8.0.3

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

Version 10.0.22621 Build 22621 - probably various versions

Did you find any workaround?

No

Relevant log output

No response

@BurkusCat BurkusCat added the t/bug Something isn't working label Jan 8, 2024
@drasticactions
Copy link
Contributor

I don't think this is specific to MAUI apps running on WinUI, this is a condition of running WinUI apps in general. WinUI apps, as far as I'm aware, don't bundle a .NET runtime and don't support things like NativeAOT right now, so you would need to have a .NET Runtime installed in order to run them. If WinUI doesn't support it, MAUI can't. This should probably be addressed in https://github.com/microsoft/WindowsAppSDK/.

@mattleibow @jonathanpeppers what do you all think? Am I missing something here?

@mattleibow
Copy link
Member

mattleibow commented Jan 9, 2024

I think you may need SelfContained and not PublishSingleFile

@BurkusCat
Copy link
Contributor Author

@drasticactions Based on my research, packaged WinUI apps have been able to bundle .NET with it for a long time. If they weren't able to, I think there would basically be no WinUI apps on the store/they wouldn't do very well because users would need to go download something extra outside of the store to get them to run. At a time, unpackaged WinUI apps didn't support including .NET but I think that has changed over the past year or so.

@mattleibow I've given that suggestion a try and got this error message:

C:\Users\runneradmin\.nuget\packages\microsoft.windowsappsdk\1.3.230724000\buildTransitive\Microsoft.WindowsAppSDK.SelfContained.targets(198,5): error MSB4018: The "GenerateAppManifestFromAppx" task failed unexpectedly. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]
C:\Users\runneradmin\.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 'D:\a\Catlists\Catlists\src\Catlists\obj\Release\net8.0-windows10.0.19041.0\win-x64\MsixContent\AppxManifest.xml'. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]

I've tried various remixes of it with other csproj, directory.build.targets, and command line settings in the pipeline + got the above error message and this one too:

C:\Users\runneradmin\.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. [D:\a\Catlists\Catlists\src\Catlists\Catlists.csproj::TargetFramework=net8.0-windows10.0.19041.0]

Are these two scenarios confirmed working:

  1. Building a packaged, .NET 8 MAUI WinUI app that doesn't require a separate .NET install (i.e. .NET is bundled within)
  2. Building an unpackaged, .NET 8 MAUI WinUI app (that either bundles or doesn't bundle .NET)

Is there a sample repository with example pipelines for these scenarios where the above has been tested in .NET8? I'm happy to pour over it and find the difference of what I'm doing wrong in my project + report back.

At the moment, I feel like I'm deep in workarounds and I'm not sure if they are helping or hindering. The most success I've gotten so far is building a packaged app that does not bundle .NET & building an unpackaged app that does not start.

@BurkusCat
Copy link
Contributor Author

When I setup my app to try debug the unpackaged app that crashes on startup (uncertain if .NET is properly bundled, I will need to get it starting first and then test on another machine), I get this error message in the console:

'Catlists.exe' (Win32): Loaded 'C:\Windows\System32\msdmo.dll'. 
The thread 0x6ad4 has exited with code 0 (0x0).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80004005, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
'Catlists.exe' (Win32): Loaded 'C:\Windows\System32\cabinet.dll'. 
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80004005, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF8013153B, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
'Catlists.exe' (Win32): Loaded 'C:\Users\burku\Downloads\artifacts-windows (3)\System.Linq.Queryable.dll'. 
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80131534, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: WinRT originate error - 0x80131534 : 'The type initializer for 'WinRT.ActivationFactory`1' threw an exception.'.
Microsoft.ui.xaml.dll!00007FFA6112E312: CallContext:[\ImageDecodeActivity\ImageDecodeActivity\ImageDecodeActivity\ImageDecodeActivity] 80131534 - Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80131534, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
The thread 0x76d0 has exited with code 0 (0x0).
The thread 0x5d60 has exited with code 0 (0x0).
The thread 0x6a00 has exited with code 0 (0x0).
Exception thrown at 0x00007FFBBAEC567C in Catlists.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x000000111FD76DB0.
Exception thrown at 0x00007FFBBAEC567C in Catlists.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFBBAEC567C in Catlists.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x000000111FD76DB0.
Exception thrown at 0x00007FFBBAEC567C in Catlists.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFBBAEC567C in Catlists.exe: Microsoft C++ exception: EEFileLoadException at memory location 0x000000111FD76DB0.
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80070002, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C in Catlists.exe: Microsoft C++ exception: [rethrow] at memory location 0x0000000000000000.
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80070002, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: 0xE0434352 (parameters: 0xFFFFFFFF80131534, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x00007FFA63C80000).
Exception thrown at 0x00007FFBBAEC567C (KernelBase.dll) in Catlists.exe: WinRT originate error - 0x80131534 : 'The type initializer for 'WinRT.ActivationFactory`1' threw an exception.'.
Unhandled exception at 0x00007FFA6171C2AA (Microsoft.ui.xaml.dll) in Catlists.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x000001EA00008A80, 0x0000000000000006).

Unhandled exception at 0x00007FFBBB4BE9FF (combase.dll) in Catlists.exe: 0xC0000602:  A fail fast exception occurred. Exception handlers will not be invoked and the process will be terminated immediately.

'Catlists.exe' (Win32): Loaded 'C:\Windows\System32\globinputhost.dll'. 

I was able to set a debugger for my app by following the instructions in these two links: https://learn.microsoft.com/en-us/visualstudio/debugger/debug-multiple-processes?view=vs-2022#BKMK_Automatically_start_an_process_in_the_debugger and using Auto 1 https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/enabling-postmortem-debugging#specifying-a-postmortem-debugger

Interestingly, with the debugger attached, the app actually can proceed past this error and will run (albeit in a very broken state with missing icons and occasional errors + broken functionality).

@Eilon Eilon added the area-publishing Issues with the app packaging/publishing process (ipk/apk/msix/trimming) label Jan 10, 2024
@jfversluis
Copy link
Member

@BurkusCat would you be able to try this with a non-MAUI WinUI app? If that shows the same behavior, then you will probably have more luck on the WinAppSDK repo. I doubt this is specific to .NET MAUI.

@jfversluis jfversluis added the s/needs-info Issue needs more info from the author label Jan 23, 2024
@ghost
Copy link

ghost commented Jan 23, 2024

Hi @BurkusCat. 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.

@jbe2277
Copy link

jbe2277 commented Jan 23, 2024

Publish of my .NET 8 / WinUI 3 application as MSIX with self contained .NET and Windows SDK works correct:

I used this to create the MSIX:

PS C:\Dev\GitHub\fhg\src\FileHashGenerator\FileHashGenerator.Presentation> dotnet publish 
-f:net8.0-windows10.0.19041.0 -c Release -p:Platform=x64 -p:ApplicationDisplayVersion=1.0.0.0 
-p:AppxPackageSigningEnabled=true -p:PackageCertificateKeyFile=C:\YourSelfSignedKey.pfx 
-p:GenerateAppxPackageOnBuild=true

This seems to be a MAUI related issue.

@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 labels Jan 23, 2024
@mosinms7711
Copy link

Any update on this?

@BurkusCat
Copy link
Contributor Author

I've created a public, GitHub fork of "maui-samples" where I've created a pipeline for the sample "weathertwentyone" app: https://github.com/BurkusCat/maui-samples/releases/tag/windows%2F1.6.1 This repo has the source code for the issue (various tags with various attempts and the actions branch shows all the attempts) and also an example artifact with the issue. The artifact also demonstrates issue #20299 where the app cannot start.

@BurkusCat
Copy link
Contributor Author

I've tried experimenting with this again and got a reliable working solution for both packaged + unpackaged apps. I'm going to close this issue in favour of a documentation improvement issue: dotnet/docs-maui#2086

I've created a PR with working, example pipelines for anyone who needs a reference: dotnet/maui-samples#442

@omghb
Copy link

omghb commented Mar 5, 2024

@BurkusCat Thank you for the information.

I was able to build my MAUI 8.0.7 app and published it successfully on the Microsoft Store. However, the App works only on the developer machine. It does not start on a “fresh” installed Windows 10 22H2 (with all updates applied).

I checked which DLLs are loaded by my App on the developer machine via Process Explorer. It loads DLLs from

  • WindowsAppRuntime (Win UI 3)
  • Microsoft.YourPhone_1.24021.105.0_x64__8wekyb3d8bbwe (.NET assemblies from Microsoft Phone Link)

image

Loading .NET assemblies from YourPhone folder seems very strange to me.

I believe the --self-contained argument does not produce a “full” self-contained MSIX image.

Have you tried this once?

Update:
The Windows SDK is missing in the MSIX. Installing the Redist 1.3.3 got the App running on the fresh installed Windows.

Update 2:
I was able to solve this by adding the following line to the MAUI App .csproj file.

<WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained>

Note: First I added the CLI argument -p:WindowsAppSDKSelfContained=true to the dotnet publish command. But then my MAUI lib projects failed to build with the error:

error MSB4018: The "GenerateAppManifestFromAppx" task failed unexpectedly.
C:\Users\...\.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 '...\obj\Release\net8.0-windows10.0.19041.0\MsixContent\AppxManifest.xml'.

@BurkusCat
Copy link
Contributor Author

@omghb I have not come across this problem when using Packaged or Unpackaged apps. Packaged apps include the dependency in its build output folder:
image

And unpackaged apps include the .dlls with the build output:
image

Out of curiosity, were you getting the issue with packaged or unpackaged apps? Were you missing the .dlls or .msixs from the screenshots above in your build output before you made that change to the .csproj file?

@omghb
Copy link

omghb commented Mar 8, 2024

@BurkusCat My issue was with packaged apps.

My learnings:

  • The parameter --self-contained includes .NET 8 in the resulting MSIX file. The MSIX file increased about 40 MB in size.
  • The parameter WindowsAppSDKSelfContained set to true includes the WindowsAppRuntime in the resulting MSIX file. The MSIX file increased again about 20 MB in size.

With both parameters set I'm able to install the MSIX file and start the App on a "fresh" installed Windows 10 22H2.

@GuidoNeele
Copy link
Contributor

As a performance tip, for unpacked apps, set Ready2Run to true. The app will start up twice as fast.

@BurkusCat
Copy link
Contributor Author

MSIX packaged:

  • Without self-contained: 31mb (75mb of msix dependencies in seperate folders)
  • With self-contained: 70mb (75mb of msix dependencies in seperate folders)
  • With self-contained and WindowsAppSDKSelfContained: 90mb (all in one msix)

Unpackaged:

  • Without self-contained: 135mb for the full folder
  • With self-contained: 226mb for the full folder
  • With self-contained and WindowsAppSDKSelfContained: 226mb for the full folder (it didn't appear to change much)

Thank you @omghb for your investigation. I think the reason I never got this problem is because although I was deploying to non-dev machines, I was deploying to Windows 11 machines only which may already have the WinAppSdk? Anyway, I've started using WindowsAppSDKSelfContained for my packaged builds now too.

I think in summary, it is generally a good idea to use --self-contained + <WindowsAppSDKSelfContained>True</WindowsAppSDKSelfContained> for both packaged and unpackaged apps.

ReadyToRun

I tried using <PublishReadyToRun>true</PublishReadyToRun> in my .csproj @GuidoNeele . But I did not observe any increase in unpackaged app size (I would have expected the app size to be bigger because it contained more AOT'd files). How did you set this up and do you see any difference in app size?

@GuidoNeele
Copy link
Contributor

Apparently this has been the default since .NET 7 (#6025 (comment)). For us it was set to false in the publish profile so we saw a gain in performance after setting it to true.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 11, 2024
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) platform/windows 🪟 s/needs-attention Issue has more information and needs another look t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants