Wednesday, September 10, 2014

Mage.exe and the *.deploy extension

Building the ClickOnce manifests using mage.exe for application files with the *.deploy extension is not straightforward. Some give up and use MSBuild.exe and the GenerateDeploymentManifest task instead.

If you want to use mage.exe alone, what you need to know is that it cannot be done. At least not with mage.exe alone. Mage.exe does not have a way to build a deployment manifest (*.application file) to download *.deploy files. You must manually edit the deployment manifest (*.application file) before signing it. Specifically, you need to add the mapFileExtensions attribute to the deployment XML element.

As an example suppose you have an executable named ClickOnceText.exe in a folder named 1.0.0.0., here is what you do:

> mage -n Application -t 1.0.0.0\ClickOnceTest.exe.manifest -fd 1.0.0.0 -cf ..\code.p12 -pwd passwd
ClickOnceTest.exe.manifest successfully signed

> mv 1.0.0.0\ClickOnceTest.exe 1.0.0.0\ClickOnceTest.exe.deploy

> mage -n Deployment -t ClickOnceTest.application -appm 1.0.0.0\ClickOnceTest.exe.manifest
ClickOnceTest.application successfully created

> notepad ClickOnceTest.application

And here is the trick. Add the mapFileExtensions to the deployment element:

<deployment mapFileExtensions="true" ... >

And then sign the deployment manifest (*.application).

> mage -u ClickOnceTest.application -cf code.p12 -pwd passwd
ClickOnceTest.application successfully signed

With this information, you should be able to write a script to do your deployment with mage.exe. Of course, you will need a way to edit the deployment manifest (*.application) XML file, from your scripting language. But that would be the topic of another post.