This week I’ve been looking further into where WinUI3 is at and specifically how it relates to both Win32 and UWP applications. Along this journey I ran into a slight issue with WinUI3 for Desktop application that simply wouldn’t run if I published and then installed the package. In this post I’m going to walk through creating, publishing, installing and running a WinUI3 application.
Let’s get started with a new application using the Blank App Packaged (WinUI in Desktop) project templated.
I’m not even going to both adding any functionality, I’m simply going to Publish the application by right-clicking on the Package project and selecting Publish, Create App Packages.
At this point I just want to generate the package for sideloading (The Microsoft Store option will generate an upload file, which is designed to be uploaded to the Store). I also unchecked the automatic updates option for simplicity.
Next we need to select which certificate to sign the package. You need to sign the package, otherwise you won’t be able to install it. If you already have a certificate you want to use, you can select that; in this case I’m going to Create a new certificate.
After creating the new certificate you need to click the Trust button so that the certificate is added to the list of trusted certificates on your computer. This is required so that you can install the application.
We then need to pick which platforms we want to build for. In this case I’ve left the defaults but of course if you’re actually going to deploy the application you’ll want to select the Release configurations.
After hitting the Create button, and waiting for what seems like an eternity, the packaging process has completed. Click on the hyperlink to launch file explorer to the folder where the package has been created.
In the output folder you’ll see there is an Msixbundle file – this is your package application. You can double-click this package to initiate the installation process.
Click the Install button to proceed.
Note that you’ll likely see this warning, indicating that the dependencies haven’t been installed – this is normally taken care of by the Store.
To address this issue, you can either run the Install.ps1 powershell script, or you can navigate to the Dependencies folder and manually install each of the dependencies.
After installing the dependencies, run the installer again – it should complete and the installer dialog will disappear. In theory the application will be launched (since the “Launch when ready” checkbox was checked). However, nothing seems to happen after the installation is completed.
If we open up EventViewer, we can see that there is a .NET Runtime error indicating that one or more assemblies belonging to the microsoft.netcore.app.runtime.win-x64 package can’t be located.
This error is likely to be a result of the trimming that is part of the publishing process. For the moment let’s simply disable the PublishTrimming option which can be controlled in the pubxml files (in the Properties\PublishProfiles folder in the project).
Now, after publishing and upgrading our application, it runs successfully.
Note that disabling the PublishTrimmed option will significantly increase the size of the application package.
Another alternative is to specify one or more TrimmerRootAssemblies in the csproj file which will exclude those assemblies from being trimmed (see this post for an example). Note that this process could be quite laborious given the number of assemblies in the package.