Wednesday, July 23, 2008

ClickOnce for just about anything

Close your eyes, take a deep breath, click your heels three times, and say, "There's no better thing than ClickOnce"

With ClickOnce releasing a new version of your software is really a piece of cake, imagine the possibilites you have when you can push a new version to all your clients at once.

ClickOnce is great if you know how to use it and get around the limitations imposed in the Visual Studio IDE. using Mage and MageUI you can build unlimited ClickOnce deployment that can deploy any application easily and quickly. Please read on to know how to leaverage the full benefits of ClickOnce and overcome the Visual Studio limitation.

If you’re building a solution that contains multiple projects, then you will have a problem creating a ClickOnce deployment for it. ClickOnce will not collect the files of your other projects in the solution. In addition if you have any additional files to add to the deployment this is currently not possible with ClickOnce because the Application Files dialogue below will not let you add files to the deployment.




Luckily there is a way out of this using MageUI.exe which is Manifest Generation and Editing Tool, Graphical Client.
(You can read more about this tool here but you don’t really need to http://msdn.microsoft.com/en-us/library/xhctdw55(VS.80).aspx).
Using this tool you can build your ClickOnce deployment using any number of files located in a folder by following the steps below.

1- Build your solution and make all of your files in one folder (dll’s, exe, doc files, pictures, everything) ex. C:\bin
2- Decide what is the publish location that you want users to install your program from for the first time (ex. \\aali\Install)
3- Copy all the program binaries from c:\bin to the publish location under a bin folder ex. file://aali/install/bin
4- Delete *.application and *.manifest from the publish bin location (file://aali/install/bin) if you have any .application or .manifest files there, then your deployment will fail
5- Start MageUI by opening a Visual studio dos window (not the regular dos window) and type Magui.exe. When MageUI start click the first icon to the left in the tool bar. This icon will help you build an application manifest. The application manifest is an xml file that lists all the files in the folder file://aali/install/bin . To create this manifest. Type the publish bin folder in the “Application Directory” text box below (ex. file://aali/install/bin) and then click populate.



6- In the Name tab , enter a name for the application and a version






7- Save your manifest using the save button. The manifest has to be signed either with a stored certificate or a new certificate. Press the save button and when prompted click New as follows



When prompted enter any name for a certificate and then press Save and then Ok

Save the manifest file to the publish bin folder (file://aali/Install/bin)

8- Now you need to create a deployment manifest. The deployment manifest will have an .application extension and must be located in the publish folder (file://aali/install) directly not in the bin folder.
9- To create he deployment manifest click the second icon on MageUI tool bar and enter a name, and version number in the name tab

10- In the Application reference tab select your application manifest using the “Select Manifest” button and select the application manifest that was created in the previous step.

In the description Tab enter the product name, and then in the Deployment options tab enter the full path for the deployment manifest as follows



Save and sign this deployment manifest using the same certificate that you created in the previous step.
When saving the deployment manifest you need to save it to the publish folder not to the bin folder.

Now any user that points to file://aali/install/PC.application will get your application installed with all its files even if there were doc files, pictures, database files.
You can set the update options from the Update Options tab which is a self explanatory tab.

If you come up with a new version to your application you can repeat the same steps above to create a new deployment file with a higher version and updates will be done automatically to those who installed your application previously.

If you encountered any problem during the save, read the message carefully and you will be able to figure out what the problem is. I had to deal with two errors one was because I did not delete *.application and *.manifest and the other because I was trying to deploy .Net libraries which are installed already on the target computer (ex. System.data.dll or System.web.dll)

To automate this process using a batch file, here are the lines that should be in your batch file. Let's assume that this batch file is called UpdateDeployment.bat and it takes four parameters


Parameter %1 = Bin Source , %2 = Config Source, %3= Destination , %4 = Version

----------------- The batch file Begin ---------------------------
cls

mage -New Application -ToFile %3\%4\pc.exe.manifest -Name "PC" -um true -pub "Ayman Company" -Version %4 -FromDirectory %3\%4\

mage -Sign %3\%4\PC.exe.manifest -CertFile "c:\ClickOnce\PC.pfx"

mage -New Deployment -ToFile %3\PC.application -Name "PC" -Version %4 -AppManifest %3\%4\pc.exe.manifest -providerUrl %3\PC.application -i true

mage -Sign %3\PC.application -CertFile "c:\ClickOnce\PC.pfx"
------------------ The batch file end --------------------------

To call your batch file you will need to provide four argument as follows

UpdateDeployment.bat c:\bin c:\config \\aali 1.0.0.1


Prerequisites:
Prerequesites are located at C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

if you have visual studio 2008 (if you can't find this location, try to guess it according to your installation of Visual studio and windows)

use bootstrap generation tool and create a prerequisite and then use Visual studio to create one boot strapper which will create one setup file that will install all the prerequisites.



And that will be it, hope that helps.