Recently I was supposed to prepare an installer of a desktop application that we develop for our customer.
First thing that came to my mind was ClickOnce – a mechanism provided by Microsoft. I was already familiar with it, so the decision was easy.
The second step was harder – how to configure ClickOnce build pipeline and how to deploy it to the server.
I didn’t find a full, comprehensive tutorial how to do that. That’s why I want to share my experience with you.
Pros and cons of ClickOnce
ClickOnce is really straightforward and quick to configure. It supports:
- The Installation of the application
- Updating the application
- Different languages
On the other hand, if you need to have more control over the installation process, then ClickOnce may not suit your needs.
More information about ClickOnce and another installers:
ClickOnce and .NET 5.0
ClickOnce is a mechanism fully supported in .NET 5.0:
Some things have changed (e.g. the way you configure ClickOnce in Visual Studio, the place where ClickOnce settings are stored etc.) so if you were familiar with ClickOnce you need to do little adjustments.
When you have your WPF application then you can publish it directly from Visual Studio:
The whole process is described here:
It will create a publish profile:
You can have many publish profiles. It gives you the possibility to have different settings for each environment or customer, allows you to specify different updates options etc. A Profile will be required during the DevOps build process.
Some of the most important parameters that need to be set:
The publish process creates a directory that contains executables, metadata and it is protected by checksum, so it is not possible to change anything manually after the publishing.
The challenge was to build the ClickOnce package in Azure DevOps pipelines.
Basics of how to configure build pipeline are described here:
After some struggle (there was a bug in MSBuild but fortunately it was fixed by Microsoft team) I managed to configure it:
To generate ClickOnce package you need to pass the path to the application project, publish profile with parameters, set the application revision (so it is incremented automatically with every build, it uses DevOps counter mechanism), publish directory and so on.
Unfortunately, some parameters must be set at the build time (because of the checksum that is generated). We cannot change e.g. the updated URL in the release pipeline. This is why we need separate builds for each environment (now we can take advantage of profile files – we can specify different settings for each environment). I don’t know if there is a better solution for this, probably not.
Pipeline should publish artifacts with ClickOnce files (manifest, some metadata, executable etc.).
The next step is to deploy it to the server.
There are some different options to host the ClickOnce installer.
I decided to host it using IIS on Windows Server.
How to install IIS:
We can use a default web page to make the files (from %SystemDrive%\inetpub\wwwroot) available via HTTP.
The first step was to create a new deployment group. Azure DevOps creates for you PowerShell script that you can execute on your server to install Azure Agent. After that you can control everything from DevOps site.
To deploy to server two steps are required:
- IIS Web App Manage
- Deploy IIS Website/App – here we need to configure what files should be copied
After a successful release setup.exe should be available via HTTP. It is also possible to configure HTTPS access or use network share (depending on requirements of your project). The application can be installed by users. It will automatically check for updates.
ClickOnce is a very good choice if you need to provide an installer and updater of your application. It is possible to fully automate the build and release process in DevOps pipeline. I believe that this article will help you to do that.