ClickOnce Extends Windows Forms Applications into Smart Client Applications, Page 2
Additionally, an HTML page is generated to provide a simple way for users to access and install your application (see Figure 5). You can e-mail users a link to the HTML page to make it easy for them to deploy.
Figure 5: Sample Generated Page
If you don't have access to Visual Studio 2005 and the Publish Wizard, you can use the manifest generation tool (mageui.exe) to generate a manifest (see Figure 6). It is more complicated to generate the initial manifests, but certainly better than trying to create them without assistance.
Figure 6: MageUI Screenshot
Checking for Updates
You can choose from several basic strategies to update your application. The following options are available:
- Checking for updates during application startup: This strategy works best for high-bandwidth network connections. Low-bandwidth connectivity will likely cause long delays that force the user to wait.
- Checking for an updated manifest file on a background thread after the application starts: This strategy works best for low-bandwidth network connections. If an update is available, the user is asked whether he or she wants to download the update the next time the application starts. This is the default strategy.
- Providing a UI for manual checking: This strategy works best when you want the user to control when the application is updated. It involves using ClickOnce APIs to program your own update.
- Blocking update checking to prevent the application from ever looking for updates: This strategy works when you want to initially deploy your application through ClickOnce, but have no desire to provide future updates.
The update strategy is controlled through the deployment manifest file. For instance, you block update checking by removing the <subscription> tag from the deployment manifest file. The following are some example deployment manifest files:
Checking for Updates after Startup
<!-- Check for updates after startup --><subscription> <update> <expiration maximumAge="4" unit="hours" /> </update></subscription>
Checking for Updates on Startup
<!-- Check for updates on startup --><subscription> <update> <beforeApplicationStartup /> </update></subscription>
Making an Update Mandatory
<!-- Forcing an Update --><deployment install="true" minimumRequiredVersion="188.8.131.52">
The easiest way I have found to control the manifest files is by first generating them through the Publish Wizard in Visual Studio 2005 and then using MAGE to update them (see Figure 7). This reduces the likelihood that you will have to manually edit the manifest files.
Figure 7: Controlling Updates Through MAGE
ClickOnce Lessons Learned the Hard Way
A number of my colleagues have gone through some ClickOnce trials and tribulations, from which they learned the following lessons:
- MageUI.exe is actually the GUI for the manifest generation tool. Mage.exe is the command-line tool. Mage.exe will open MageUI.exe if no parameters are specified.
- If the build type (debug or release) or the target platform changes, it breaks compatibility with older versions of the manifest.
- Programmatically using the ClickOnce namespace will require more than the minimum level of .NET trust for the executable.
- Content files and referenced assemblies from the GAC (Global Assembly Cache) are not automatically included in the deployment.
- You can select the "Sign the ClickOnce manifests" option in project properties. This will verify that files are copied/downloaded intact. However, this prevents changing config files without resigning with Mage.
ClickOnce Enables Smart Clients
You now have a general idea of how to use ClickOnce to help enable smart client applications. You covered the background of ClickOnce and walked through an example deployment to a network file share. You also took a brief look at the manifest generation tool. Although the use of security permissions within the installation is beyond the scope of this article, I suggest you learn the security settings before using ClickOnce.
The topic of the next column is yet to be determined. If you have something in particular that you would like to see explained here, e-mail me at email@example.com.
About the Author
Mark Strawmyer (MCSD, MCSE, MCDBA) is a senior architect of .NET applications for large and mid-sized organizations. Mark is a technology leader with Crowe Chizek in Indianapolis, Indiana. He specializes in architecture, design, and development of Microsoft-based solutions. Mark was honored to be named a Microsoft MVP for application development with C# for the second year in a row. You can reach Mark at firstname.lastname@example.org.