Output an app created with WinUI 3 so that it can run in a standalone EXE format
Operating environment
- Windows
-
- Windows 11
- Visual Studio
-
- Visual Studio 2022 Version 17.12.3
- .NET
-
- .NET 8
- WinUI
-
- WinUI 3
- Windows App SDK
-
- 1.6.3 (1.6.241114003)
Prerequisites
In some cases, lower versions may also work.
- Windows
-
- Windows 10
- Windows 11
- Visual Studio
-
- Visual Studio 2022 version 17.12 or later
- .NET
-
- .NET 8 or later
- Windows App SDK
-
- 1.6.0 or later
At first
Applications created with WinUI 3 are typically packaged applications that can only run under special circumstances. To run it, you need to download and install it from the Microsoft Store. There is also a method of distributing files directly, but it requires somewhat complicated procedures and settings, and is not suitable for distributing to an unspecified number of people. Instead, you can run your application in a highly secure environment.
The method introduced this time allows you to create an EXE file by unpackaged method, so you can distribute the EXE file to the user as it is and execute it. If you want to make an application written with WindowsForm or WPF look the same way you want it to be distributed, this approach is the way to go.
Attention
WinUI 3-related products are constantly being updated, so they may not work well due to different versions. I think that this procedure will work if you match the IDE and SDK versions, but if it does not work well, please pay attention to various versions.
In addition, programs written with unpackaged have some limited functionality compared to packaged programs. It is difficult to explain the details, so please check if it works according to the program you created.
precondition
- Follow the tips "Prepare to develop with WinUI 3" to assume that your environment is set up.
Update Visual Studio 2022
Basically, there is no problem as long as you have the latest version. At least the version at the beginning of this article. Run it from the Visual Studio menu or launch the "Visual Studio Installer" from the Start menu to update it.
Install the Windows App SDK (Windows App SDK)
The Windows App SDK that is included with Visual Studio installation is outdated and should be up to date. Please download and install it from the following site.
When executed, the batch will be launched and updated without question.
Create a project
After that, create the program you want to create. This section describes the state of the new project.
Bring the package version up to date with NuGet
Make sure that the version of "Microsoft.WindowsAppSDK" is at least the version at the beginning of this article. There is no problem with the included "Microsoft.Windows.SDK.BuildTools" being up-to-date.
If you want to update, you can do so from the NuGet managed package.
Disable the package
Open the project properties.
In the category of "Application > Packaging", there is an item called "Enabled MSIX Packaging for this Project", so uncheck it.
Try it out
If you look at the debug execution of the toolbar, I think it is "XXXX (Package)". You can change it to "XXXX (Unpackaged)" from the choice, so change it to Unpackaged.
Once you have changed it, try running it. If you can run it without errors, there is no problem.
Generating an EXE File
You can distribute the EXE file that is generated after building, but this time I will output the executable file from the "Publish" menu.
By the way, in order for the "publish" process to be performed successfully with unpackaged, you need to use the ". NET Desktop Development.
Right-click the project and choose Publish.
If you are starting with a new project, you will have three profiles created from the beginning, so you can select the environment that you want to deploy to. If you are updating a project, etc., there may not be a profile, so in that case, create a new profile.
From More Actions, select Edit.
For some reason, the settings are different from the profile, such as the initial settings, so match the profile as follows.
Parameter name, | setting value, remarks | |
---|---|---|
configuration | Release xXX | Please change it according to your profile. If it's win-x64, it's Release x64. |
Target Framework | Align with your current project | |
Deployment Modes | Self-contained | In the current specification, only "self-contained" works. |
Target Runtime | win-xXX | Please change it according to your profile. If it's win-x64, make it win-x64. |
Target Location | Leave the default value | |
Creating a single file | off | Under the current specification, it cannot be executed even if it is created in a single file. |
ReadyToRun | arbitrary | Check it out if you want to improve performance. |
Trimming Unused Code | arbitrary | Check it if you want to reduce the file size. Note that it will not work depending on the creation of the program. |
When you are done, click the "Submit" button.
Verify that the publication was successful without errors.
You can open the published file by clicking the Target Location link.
If you can run the EXE file and start it, you're good to go. If you want to distribute, you need to take the full set of files in this folder. 「. It is okay to delete files that are not necessary for execution, such as ".pdb" files.