Sunday, September 21, 2008

ClickOnce, Nant and Multiple Configurations

So. My first post that's NOT about troubleshooting unit testing. 'bout time, huh :) This post is about deploying applications using ClickOnce. On my current project we used to deploy the application to a network share using the 'publish' functionality in Visual Studio. It works, but there are several problems with this approach. A better idea is to deploy the application from the build server. I wont delve into the arguments, as they'are all out there. This meant extending our current build script somewhat.

We deploy a test version of the application fairly often. Obviously, it needs to be configured differently than the production version. The first differences that came to mind in our scenario was connection strings, web service URLs and the title of the main window (to make clear whether the program is the test or production version). Also, a requirement for the deployments was that users could install both the production and test version of the program side by side on the same machine. Because of that there was a few more subtle things that needed to be handled. I struggled a bit few these when creating the build script, so I write this post alot for my own reference.


Nant + ClickOnce + msbuild

Each build is scripted using Nant and produces two deployable releases of the software (inspired by these posts by Kyle). The following Nant task can be used to invoke the msbuild 'publish' target for the project in question. The 'PublishDir' property is used to control where the resulting files should be put.


<msbuild project="${project.file}">
<arg value="/t:publish" />
<arg value="/p:PublishDir=${current.release.dir}\" />
</msbuild>

I actually provide a few more properties to msbuild, but I'll get back to that.


Multiple Configurations

I mentioned that the two versions need different configurations. The stuff that's in app.config are easily changed using Nant's xmlpoke task, but there's an important point here. Changes to any file in the clickonce deployment must be performed BEFORE the manifests are signed, or else the installation will fail. I found two options at this point. Either store a single copy of all the relevant files on disk until it's time for deployment and perform app.config changes and manifest generations on the fly using mage.exe. Or the second option, which I chose (dont't ask why), which is to generate and store two clickonce packages, both by using msbuild, but with different app.configs.


Side by side installation

The more subtle issues that i struggled with appeared when trying to install the two versions side by side on the same machine. Turns out, that the assembly names of the two versions must differ. If my application has an entry point assembly called MyApplication.exe, I had to name the test version something else. If I didn't, ClickOnce would overwrite the production version when I installed the one for test. You can tell msbuild what you want the output assembly to be called by providing a value for the 'AssemblyName' property like this:


<msbuild project="${project.file}">
<arg value="/t:publish" />
<arg value="/p:PublishDir=${current.release.dir}\;AssemblyName=${assemblyname}" />
</msbuild>

That only works if the application lives in a solution by itself, because now all the projects in the solution will get the same assembly name. I got around that issue by putting a conditional PropertyGroup inside the MyApplication.csproj file:



<PropertyGroup Condition=" '$(AssemblyNameOverride)' != '' ">
<AssemblyName>$(AssemblyNameOverride)</AssemblyName>
</PropertyGroup>

Combined with providing the AssemblyNameOverride property to msbuild instead of AssemblyName like before, only the correct assembly changes name:



<msbuild project="${project.file}">
<arg value="/t:publish" />
<arg value="/p:PublishDir=${current.release.dir}\;AssemblyNameOverride=${assemblyname}" />
</msbuild>

Now the two versions can be installed side by side without overwriting each other, except that they still overwrite each other's start menu shortcuts. To avoid that I provide the ProductName property as well. I also use the PublishUrl property to tell where to look for updates. The final msbuild task looks like this:



<msbuild project="${project.file}">
<arg value="/t:publish" />
<arg value="/p:AssemblyNameOverride=${assemblyname};PublishUrl=${clickonce.url};PublishDir=${current.release.dir}\;Configuration=Release;ApplicationVersion=${CCNetLabel};UpdateRequired=true;ProductName=${clickonce.productName}" />
</msbuild>

Conclusion


It's better to deploy stuff from the build server than from developer workstations. You can use Nant (or other build tools) to generate builds for different environments, but when using ClickOnce a few steps need to be taken. I hope this post saves someone some time, as I spent quite a while figuring this stuff out :)

UPDATE: You can download a simple example here. You need to set up some shared folder on your computer to try it out (I haven't found a way to clickonce deploy to a local folder).

3 comments:

Anonymous said...

Wanna Get HIGH? Running out of Supply? Then Check Out My Shit!
>>>>> http://bestlegalhighsdrugs.info <<<<
If you have questions, you can email my boy at online.mentor [at] gmail.com


[size=1] IGNORE THIS----------------------------
Herbal Smoking Alternatives ecsyasy oills [url=http://bestlegalhighsdrugs.info] buy legal highs [/url] salvia divinorum akanita uscaria [url=http://buybudshoplegalherbs.info] buds shop[/url] pneumatic detach meth alvia divinoruum [url=HTTP://BUYINGMARIJUANASALE.INFO] Marijuana Sale [/url] pregnancy test strips plug ecstasy [url=HTTP://BUYLEGALBUDSCOMREVIEWS.INFO] legal buds [/url] Does Salvia Show Up On Drug Tests shroom [url=HTTP://CANNABISHIGH-PILLSHIGH.INFO] Marijuana Effects[/url] ecsrasy pilld fly agaric experience [url=HTTP://HOWTOBUYWEED-BUYINGWEED.INFO] how to purchase weed online[/url] ldgal vuds elgal bjds [url=http://legalbud.drugreviews.info] legalbud [/url]

amantia mjscaria sallvia divinoruk [url=http://legalweed.lamodalatina.com] legal weeds [/url] There Are Also Other Considerations Like Which Kind Of Salvia? drug abuse [url=http://buysalvia.lamodalatina.com] purchase salvia powder[/url] purple rain soundtrack ayahuacsa

amanita muscsria how to use salvia extract [url=http://legalweed.lamodalatina.com] legal weeds [/url] maanita mudcaria ecstaasy pilsl [url=http://buysalviacheap.com] order salvia leaves[/url] dcstasy oills Maui Hybrid Buds
[url=http://guaranteedheightincrease.info/]height improvement[/url] - http://guaranteedheightincrease.info/
height increase - http://guaranteedheightincrease.info
[url=http://provenpenisenlargement.info/]proven penis growth[/url] - http://provenpenisenlargement.info/
proven penis enhancement - http://provenpenisenlargement.info/
[url=http://provenskincareadvice.info/]skin care advice[/url] - http://provenskincareadvice.info/
skin care tips - http://provenskincareadvice.info/
[url=http://getrichgambling.info/]get rich gambling[/url] - http://getrichgambling.info/
get riches gambling - http://getrichgambling.info/
[url=http://herpesoutbreak-gentalwarts.info/]herpes outbreaks[/url] - http://herpesoutbreak-gentalwarts.info/
herpes outbreak - http://herpesoutbreak-gentalwarts.info/
[url=http://STOP-PREMATURE-EJACULATION-SOLUTIONS.INFO]stop premature ejaculation[/url] - http://STOP-PREMATURE-EJACULATION-SOLUTIONS.INFO
cure premature ejaculation - http://STOP-PREMATURE-EJACULATION-SOLUTIONS.INFO
[url=http://3GMOBILEPHONESFORSALE.INFO]used mobile cell phone on sale[/url] - http://3GMOBILEPHONESFORSALE.INFO
used mobile phone on sale - http://3GMOBILEPHONESFORSALE.INFO
[url=http://internationaloddities.reviewsdiscountsonline.com] international oddities scam[/url]
internationaloddities review
[url=http://drobuds.reviewsdiscountsonline.com]review of dro buds [/url]
buy dro buds
[url=http://bestacnetreatmentreviews.info] acne treatment review[/url] http://bestacnetreatmentreviews.info
acne treatment review http://bestacnetreatmentreviews.info
[url=HTTP://LEARN-HYPNOSIS-ONLINE.INFO]learn hypnotism online[/url]
learn hypnosis online

Anonymous said...

free sex dating services [url=http://loveepicentre.com/]dating game by icp[/url] yoho personals http://loveepicentre.com/ confidence dating

Anonymous said...

I am able to make link exchange with HIGH pr pages on related keywords like [url=http://www.usainstantpayday.com]bad credit loans[/url] and other financial keywords.
My web page is www.usainstantpayday.com

If your page is important contact me.
please only good pages, wih PR>2 and related to financial keywords
Thanks
hacyenjoync