So in my struggling to get a lean and effective way to roll out new versions of an application for two of my clients, I have some more to share with you. I want it to be extremely easy for me to create a new ClickOnce installer for my clients and I have identified three things that I need to solve:
- The installations will be run from different installation URL:s.
- Getting unique config-files packed with the ClickOnce publish. I have 2 clients, each with a test and a production environment, and I need to handle my own test environment too.
- A client machine needs to be able to run installations for both test and production on a single machine. This means that ClickOnce must see my applications as different applications even though it is only one.
I have solved the last two, so lets start with the last one.
Running both test and production environments on the same client
There are more than one way to solve this, but for me the easiest solution was to create two Visual Studio projects. Originally I had a single Windows Forms exe project in Visual Studio, but I changed this to be just a DLL-project (Output type in Application settings). Then I created two new projects with the names Application and Application.Test and for both of them I configured ClickOnce as usual. There is only a single line of code in each of these projects and that’s to call the original entry point in my old exe-project:
Program.Main(args);
With this solved I still needed to handle the differences in configurations.
Different config for each environment
Visual Studio 2010 has support for transforming configuration files when deploying a web project, but only when deploying and that is only supported for web projects. Luckily Sayed Ibrahim Hashimi and Chuck England have created a small VSiX called SlowCheetah XML Transforms that do the same thing, but when you build your project. So naturally the first step is to install the add-in. Next up is to create new project configurations in configuration manager (I created CustomerATest, CustomerAProd, CustomerBTest and CustomerBTest). With this in place you can right-click on the config-file in you project and select Add Transform, which adds a sub-config file for each configuration. In these config files you then apply the transformations for the changes you want to do in the config file.
This is so useful in many more scenarios than just for deploying with ClickOnce.
Unfortunately I haven’t solved the problem of having different installation URL:s for each configuration, but maybe someone has a tip? I have tried to edit the project file and move the installation url element to respective configuration. This works if I remember to reload the project each time I select another configuration (which I of course don’t), but if I don’t reload the settings will be overwritten with the value from the configuration that was used when the project was loaded so that won’t work. The best thing would of course be if Visual Studio could start to support different installation URL for each configuration.