Project: UWP App (C#) - how to compile UWP app to share it and run it on a another computers
Hello!
I came to conclusion that before proceeding with the development of the application in this guide, I should tell you how to compile and release such application for others to be able to use it. For UWP apps, this is a bit more difficult than simply compiling the .exe file.
From Visual Studio, a UWP app can be bundled or published to the Microsoft Store. The second option, however, is a more complicated process that requires a developer account, so I'll cover it in another future article. Compiling to a package is enough to publish the application outside the Microsoft Store, or share it with friends.
How to do that?:
In the Solution Explorer, click on our application (as a whole) with the right mouse button. Then select Publish -> Create application packages:
Then a new packaging window will open.
On the first screen we have to choose a distribution method. Let's select Local Download (the second option, I don't know how it's originally called). We can also turn off automatic updates. Then click "next":
On the next screen we need to select a certificate. Without it, the installation of our application will not be possible. Let's choose "Yes, choose a certificate":
If we do not have any (trusted) certificate (in a file or in the Azure cloud), we must create a test certificate that is valid for one year. Select the "Create" option. A screen will appear where you enter your name and a password for the certificate:
After providing these details and confirming everything, the certificate will be added. We will be able to use it when creating a package for this application. The wizard window should look something like this:
Let's leave SHA256 in the Encryption Algorithm field. We also don't need to provide any timestamp server URL.
Click "Next" in the lower right corner. This screen will appear:
In the first field from the top we can choose the starting location. I will leave the default one.
Below we can enter the version of the application. If you leave the "automatically increment" option enabled, Visual Studio will automatically increment the last two version numbers of the application with each subsequent build to the package.
Under "Generate application package" (green arrow) select "Always".
Below (red arrow) we can set the processor architectures for which we'll create the package. I recommend leaving only the first three options - x86, x64 and ARM. Most computers use the x86 or x86-64 architecture (Intel, AMD processors), with most being 64-bit nowadays. Therefore, we should always choose the first two options. ARM is the processor architecture used by mobile and IOT devices (e.g. phones, tablets, Raspberry Pi, Windows 10/11 ARM OS devices). We don't have to select this option, but we can do it to increase compatibility.
On the right side of the table (red arrow too), select the deployment configuration. We can choose between Release and Debug. However, I recommend choosing Release, because Debug is for testing by developers. Selecting Debug would also increase the size of the generated package.
The last option "Include public symbol files (...)" is not necessary, I don't check it although you can do it.
After selecting all these options, let's click "Create" in the lower right corner. The wizard window closes and Visual Studio starts compiling. This can take many minutes, on weaker computers and with very complex programs even hours. Do not close Visual Studio or turn off your computer until the process is complete.
When the process is finished, a pop-up window will appear with information and a link to the location on the disk:
A folder was created in this location, with files used in the possible installation process:
This (parent) folder (in this case "ApplicationUWP1_1.0.0.0_Test") can be put, for example, into a ZIP file and published together with the installation instructions (which I wrote in this post below).
How do I install a UWP application compiled this way on a Windows 10 or 11 PC?:
If we used a trusted certificate, a bundle file (.msixbundle) should suffice. In this case, however, it will not work due to the lack of a trusted certificate. Below is the result of trying to run this file:
As you can see, this package doesn't work because I used a test certificate.
So how do I install a UWP app signed with a test certificate?:
1. You must be on the administrator account. Enable developer mode in the settings, at least for the duration of the installation process.
2. Run the file "Add-AppDevPackage.ps1" in Windows PowerShell. Right-click on it and select "Run in PowerShell". Note: the application folder must be unpacked, do not run this file for example in a ZIP archive.
3. PowerShell will start. Follow the instructions it displays. Give it administrator rights and in the second instance of the terminal that opens, confirm the installation of the certificate:
After confirming all this, the certificate and application will be installed. You can find the application in the Start menu and start using it.
That's all for this article. In case of problems or questions, please write in the comments. thank you.
- Wojtekb30
(18.12.2022)
Post translated with my Blogger HTML Post Translator: https://github.com/Wojtekb30/Blogger-HTML-post-translator
Comments
Post a Comment