Application Development using ClickOnce in Visual Studio 2005

1.Scope
 

Web based application are preferred way of developing application compared to Windows based application development today. Even though the windows based applications gives you advantages like rich user interface, performance, ability to run offline, efficient use of edge resource (Client machines) and easier integration with local applications and APIs, web based application was preferred mechanism as they are more easier to deploy and update compared to desktop applications.

 

The other advantages of using web application is they do not have any installation to be made on client machine which relieve them of the problems like DLL hell and interference with other applications on the client system. 

 

The purpose of this article is to show how ClickOnce technology changes our perspective towards windows application deployment, and also to explain the steps to deploy an application using ClickOnce.

  

2.Introduction
 

ClickOnce is a new application deployment technology introduced in Whidbey (Visual studio 2005) and is built on top of "No-Touch deployment" feature provided by .Net 1.1. It also uses the MS Updater Application Block


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


image008.gif

                                
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

  1. From the Build menu select "Publish ClickOnceTest"

image009.jpg

 

  1. 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/. 


    image010.jpg

  2. 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".

image011.jpg

 

  1. In the next screen click finish on the dialog which will complete the wizard and publishes the application on the selected location.

image012.jpg

 

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.

image013.jpg

 


Step 3: Deploying and Running the application

 

  1. 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.

  1. Click on the "Install" button.
  2. Below would window would be displayed, Click on "More Information" link in the right bottom corner of the window.

 

image014.jpg

 

  1. Below window would be displayed which gives the details about the application that is being installed. Click on "OK" button.

 

 

image015.jpg

 

  1. Click on the "Install" button in window displayed in "step 3".
  2. The application would be installed in the client system and started automatically.
  3. Once you have installed the application, You can invoke the application from the startmenu->programs->Wipro->ClickOnceTest

 

Step 4: Updating the application

 

  1. Go back to the Visual studio IDE.
  2. Change the "Back color" property to the button to "Indian Red"

image016.jpg


  1. Build the application.
  2. Select "Publish ClickOncetest "from the Build menu.
  3. 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.

 

  1. From the Client machine startmenu->programs->Wipro->ClickOnceTest click on "ClickOnceTest"
  2. 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.

 

image017.jpg

 

  1. 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.

image018.jpg

 

  1. Click on the Change/Remove button.
  2. The below window would be displayed given the option to revert back to previous version or remove the application completely.

 image019.jpg

 


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.

 

image020.jpg

 

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:

 

image021.jpg

 

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:

 

image022.jpg

 

Options: Adjusts details such as Application language, Publisher name, Deployment web page, whether application should automatically run after installing etc

 

image023.jpg

 

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:

 

image024.jpg

 

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


ClickOnce - Everything you ever wanted to know about:

http://dotnetjunkies.com/WebLog/nenoloje/archive/2005/01/20.aspx

 

Smart Cllient development center

http://msdn.microsoft.com/smartclient/understanding/windowsforms/2.0/features/clickonce.aspx

 

The Magic of ClickOnce: http://www.ondotnet.com/pub/a/dotnet/2004/10/11/clickonce.html?page=1

 

No-Touch deployment:

 

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchNo-TouchDeploymentInNETFramework.asp

 

Introduction to Updater Application Block:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/uabch1.asp


Updater Application Block:

http://www.microsoft.com/downloads/details.aspx?FamilyID=c6c17f3a-d957-4b17-9b97-296fb4927c30&displaylang=en 


Updater Application Block Version 2.0

http://www.microsoft.com/downloads/details.aspx?FamilyID=C6C09314-E222-4AF2-9395-1E0BD7060786&displaylang=en  

 

ClickOnce FAQ

http://www.windowsforms.net/FAQs/default.aspx?PageID=1&CategoryID=24&tabindex=2  

Up Next
    Ebook Download
    View all
    Learn
    View all