http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/uabch1.asp
ClickOnce makes deploying a Windows Forms based application as easy as deploying a web application. With use of "ClickOnce" running a Windows Forms application is as simple as clicking a link in a web page. For administrators, deploying or updating an application is simply a matter of updating files on a server; there is no need to individually touch every client system
Architecture of ClickOnce:
When a user accesses a Launched ClickOnce application, he or she actually clicks a link that points to the deployment manifest file. The deployment manifest has an ".application" extension. Web servers with the .NET Framework 2.0 installed include a MIME filter for this file type that invokes the Deployment Framework Service (DFS). The DFS is a .NET Framework component that runs on the Web server where the ClickOnce application is published. The DFS reads the deployment manifest, locates the current version of the application from the application store, and launches it.
In an Installed deployment scenario, a client-side .NET Framework component executes every time a user runs the application. You see the component identified in the graphic as the Startup SHIM. The SHIM reads a locally-cached copy of the deployment manifest to find the update settings for the application. Its initial job is to answer the question, "Do I need to check for updates?" If the answer is no, the application loads from the local program directory, and the work of the SHIM is done. However, if the update settings in the manifest do call for an update check, the SHIM reads the location of the deployment provider (the URL for the original deployment manifest) and calls it to determine whether an update is available. If the application is up to date, the SHIM launches the application from the local program directory. If an update is available, the application gets updated.
3.Walk through: Deploying application using ClickOnce
Step1: Create a windows Application
1. Open Visual Studio 2005.
2. Select a new project from file menu
3. Choose a language (C#) and select Windows Application.
4. Name the project ClickOnceTest and click OK.
5. Add a button to the form and change its Text property to "About" using the properties window.
6. Double-click the button. In the code Window enter the following code
MessageBox.Show("ClickOnce Application");
7. Build the Application and Run it.
Step 2: Publishing on a web server
- From the Build menu select "Publish ClickOnceTest"
- A wizard comes up prompting to select the location to publish this application.
Choose the preferred option in this case I have choose IIS hosting on local machine so the location would be http://localhost/ClickOnceTest/.
- The next screen you have an option of selecting the application to run online or offline.
If available online and offline the client would keep a copy of application in the assembly cache and run the application when the system is offline (Not connected to internet).
In case of only available online you would not be able to run the application when the client is offline.
In our case we want to make the application available even when the client system is offline so we
would select the first option "Yes".
- In the next screen click finish on the dialog which will complete the wizard and publishes the application on the selected location.
Note: As we did not sign our application the wizard would automatically sign the application and publish it on the website.
6. After publishing the application the IE windows would be displayed with the link to the application as shown below.
Step 3: Deploying and Running the application
- Open an IE window and navigate to http://localhost/ClickOnceTest/publish.htm
Replace localhost with <systemname> accordingly if you have published on a different system location.
- Click on the "Install" button.
- Below would window would be displayed, Click on "More Information" link in the right bottom corner of the window.
- Below window would be displayed which gives the details about the application that is being installed. Click on "OK" button.
- Click on the "Install" button in window displayed in "step 3".
- The application would be installed in the client system and started automatically.
- Once you have installed the application, You can invoke the application from the startmenu->programs->Wipro->ClickOnceTest
Step 4: Updating the application
- Go back to the Visual studio IDE.
- Change the "Back color" property to the button to "Indian Red"
- Build the application.
- Select "Publish ClickOncetest "from the Build menu.
- The Wizard would be displayed again, choose Finish in the wizard to take the previous configured values.
This will complete the publishing of the updated version of the application on the server.
- From the Client machine startmenu->programs->Wipro->ClickOnceTest click on "ClickOnceTest"
- Below window would be displayed prompting the user that an updated version of the application is available for download, Do you want to download it now? , Click "OK" to update the application.
- The updated version of the application would be installed and runs automatically.
The user has an option of reverting back to one version prior to the installed version in case he finds the older version more useful. This can be done by running appwiz.cpl from "start->run" option and select the appropriate program to revert back.
- Click on the Change/Remove button.
- The below window would be displayed given the option to revert back to previous version or remove the application completely.
4.Tweaking the default behavior
Till now we have seen the default behavior given by the ClickOnce wizard. To modify the default behavior change the settings choose properties of the project and select publish Tab.
Publishing Location indicates where the application will be deployed to. It can be a Web server (HTTP) location, as shown above, Ftp location or any network share.
Install Mode and Settings gives option to controls several deployment details, such as:
Is the application will be available online only or offline as well.
Application Files: Where individual files will be installed.
Prerequisites: Whether the setup program must install other components, such as Windows Installer 2.0, .NET Framework 2.0, J# Redistributable Package, SQL Server 2005 Express, Crystal Reports, Microsoft Data Access Components 2.8 etc as shown in screen below:
We can add our custom MSI files as pre requisites for the install.
Updates: Controls when the application should check for updates and how those updates are brought to the client as shown in screen below:
Options: Adjusts details such as Application language, Publisher name, Deployment web page, whether application should automatically run after installing etc
Publish Version adjusts the application version number; the version number can be automatically increased at each deployment.
By default, a ClickOnce application receives Full Trust permissions when it is installed or run on a client computer. While there may be cases where Full Trust permissions are actually necessary, granting Full Trust permissions usually isn't a good idea for two important reasons:
- An application with Full Trust permissions has unrestricted access to resources such as the file system and the registry, potentially allowing your application (and the end user's system) to be exploited by malicious code.
- When an application requires Full Trust permissions, the end user will be prompted to grant permissions to the application; this means that the application is not truly a ClickOnce experience, and the prompt can potentially be confusing to less experienced users.
To exclude or include permissions:
1. With a project selected in Solution Explorer, on the Project menu click Properties.
2. Select the Security pane, to open the Security screen as shown below:
3. Check the Enable ClickOnce Security Settings checkbox.
4. In the Zone your application will be installed from dropdown list, select the (Custom) security zone.
The Permissions required by the application table will be updated with no permissions enabled.
5. In the Permissions required by the application table, select the row for the permission that you want to modify, then choose Exclude or Include from the dropdown list in the Settings column.
Any permission that has been modified will be displayed in bold text in the Permission column.
Click the Properties button, to set the properties for selected permission.
In order to effectively configure security permissions, it helps to know exactly which permissions your application requires. You can use the Permission Calculator tool, accessible from the Security pane, to analyze your code and determine the exact permissions required by your application.
Note: The tool performs a static analysis of the code and cannot determine permissions required for late-bound code or for dynamically loaded assemblies. Any existing permission settings will be overwritten.
5. Programming in ClickOnce
Clickonce also provides us with an API for customizing the download mechanism for custom scenarios.It has provided System.Deployment Namespace which contains classes and methods for customizing the behavior.The primary type that you would use is ApplicationDeployment. ApplicationDeployment contains a few key methods for programmatically controlling updates. The CheckForUpdate method returns a Boolean value that tells you whether an update is available for the application. GetUpdateCheckInfo performs the same basic task but returns an UpdateCheckInfo object that provides detailed information about the update.You call the Update method to actually install the update.You can use both synchronous and asynchronous forms of the CheckForUpdate and Update methods.Obviously, this API will work only for an application that was deployed through ClickOnce. The IsNetworkDeployed property of the ApplicationDeployment class will be true if the application is enabled as a ClickOnce application
6.Advantages of ClickOnce
Low impact: Clickonce deployment is very low in impact of other application as they run in their own sandbox.
Security: Uses .Net CAS (Code Access security) security feature.
Deployment: This is as simple as deploying a web application user has to just click on a link to run the application.
Update: Just need to update the server no need to update clients.
Bootstrapping: ClickOnce also help in doing bootstrapping process where the client needs to upgrade to .Net frame work or need certain components to be installed to support the application.
Tight IDE Integration: You can publish a ClickOnce application directly from the IDE.
7. ClickOnce Deployment Limitations
Although ClickOnce deployment works well for most applications, there are some situations where Windows Installer is more appropriate.The following are some limitations that you should be aware of:
|
ClickOnce |
Windows Installer |
Application installation location |
ClickOnce application cache |
Program Files folder |
Install for multiple users |
No |
Yes |
Install shared files |
No |
Yes |
Install drivers |
No |
Yes (with custom actions) |
Install to Global Assembly Cache |
No |
Yes |
Add application to Startup group |
No |
Yes |
Add application to Favorites menu |
No |
Yes |
Register file types |
No |
Yes |
Access registry |
No (can access HKLM with Full Trust permissions) |
Yes |
Binary patching of files |
Yes |
No |
Install assemblies on demand |
Yes |
No |
8. Future of ClickOnce
The following features support would be provided in future ClickOnce development.
Compression support: Compressed download support for large files based on Based on HTTP compression.
On-Demand APIs: More programming support.
VS signing support: Signing the Application through IDE.
SDK Manifest editor: Easier editing for manifest files.
Improved Logging: Would provide improved logging for debugging and troubleshooting.
BITS 2.0: Click once would be using Background intelligent Transfer service on Vista (formerly longhorn) and Windows Server 2003 for downloading the file.
http://www.microsoft.com/downloads/details.aspx?FamilyID=B93356B1-BA43-480F-983D-EB19368F9047&displaylang=en
9. Conclusion
In this article, I have talked about the advantages of click once and how to deploy ClickOnce application. You have to note that ClickOnce is not a complete replacement for MSI. MSI would be preferred mechanism for installing applications like drivers and applications which include large number of file (huge data).
10.Additional references