Use clickonce to deploy Windows Forms applications

Source: Internet
Author: User

Mauro Sant 'Anna
Microsoft Regional Director

Summary: View clickonce technology, compare it with other deployment technologies, and demonstrate how to use this technology in applications.

Introduction

Clickonce is a new windows form deployment technology included in Visual Studio 2005. This technology uses a smart client to simplify the installation and upgrade of Web applications. Since the first version of. NET Framework, Windows Forms applications have been deployed over HTTP and have been in development since then. This article discusses the advantages of Windows Forms applications and the technical progress of form applications that cause clickonce. I will also use the released Visual Studio 2005 Beta 1 to demonstrate a simple example.

Why use Windows Forms?

Due to the emergence of the World Wide Web, most users and developers are more interested in Web applications than "conventional" Windows applications. In addition to the cool factor, web applications also have some fascinating special features:

Web applications can be accessed anywhere in the world with Internet connections, and the client does not even need to run Windows. "Pure Web" applications are a good technology when your applications require common access.

Web applications are easy to deploy and update: you only need to copy application files to the Web server directory, and all your clients can start using new applications immediately. It works well without DLL hell, unclear registry items, and COM classes to be registered!

This article focuses on deployment. The HTTP protocol used by Web applications has many advantages over traditional Windows application deployment.

On the other hand, just like I love web, it is hard to say that the user experience on web is the first stream. Compared with Windows applications, web applications also have several shortcomings:

Its user interface is very simple. Some of the functions that take for granted in Windows applications (such as drag-and-drop and right-click) are difficult to operate or even cannot be implemented in Web applications.

Even if we try to implement a variety of interface skills, we usually need a lot of client scripts (a very difficult code to write and debug ).

Web applications use a large amount of server resources, bandwidth, and user patience, because most of the tasks are executed on the server and require round-trip and waiting.

Printing is also limited by the "Screen Printing Technology". Because of the differences in fonts, margins, and paper sizes, many operations (such as paging) are almost uncontrollable.

Although some of these problems can be mitigated by using plug-ins or ActiveX controls, in turn, there may be some deployment problems, which are the same as the previous deployment problems of non-web applications.

What if we combine the ease of distribution of Web applications with the rich client experience of Windows applications? Well, we can combine them. From the first version of. NET Framework, it allows distribution of Windows Forms applications over HTTP without common problems.

This type of application is especially suitable for Intranet/exists environments that do not require common access. We assume that all end users' computers will have Internet Explorer and. NET Framework installed.

. NET Framework 1.X: Hrefing. Exes

Both. NET Framework 1.0 and 1.1 are "out-of-the-box" and can be used to deploy Windows Forms applications over HTTP. You only need to use the "href" flag to point to the managed. EXE. Internet Explorer and. NET Framework runtime libraries can download and run executable files and their required DLL files as needed. This type of deployment is nicknamed "hrefing EXE ".

The following is an example of this tag:

<a href="MainProject.exe">Call MainProject</a>

Marking is very simple. We recommend that you refer to the following articles, which have already been discussed:

Security and versioning models in the Windows Forms engine help you create and deploy smart clients by Chris sells; you can also refer to his smart client Wahoo! Sample

Death of the browser? By BILLY holis

My article deploy Windows Forms on the Web

Using Windows Forms controls in Internet Explorer

Because. Net assembly (. EXE or. dll) is a basic deployment unit, you need to split the application into Master. EXE and multiple DLL. In this way, if you make a simple modification to a single DLL, you only need to download the DLL.

It sounds easy, but you still need some skills to make it work right:

The. NET Framework must have been installed on the client before (although you can download the plug-in from the http://msdn.microsoft.com/vstudio/downloads/tools/bootstrapper/ to make it easier to install the framework and your applications ).

Your application runs on the client as part of the trusted code. On the one hand, this is very suitable because the application runs in the sandbox and can restrict its operations on the client computer. On the other hand, if you need functions such as opening a local file or calling a COM object, you must set a security policy on the client in some way. This is important.

By default, executable files are likely to try to load multiple DLL files containing localized resources. Due to some problems in the current implementation, performance will be affected (especially in slow Internet connections ).

Updates are based on files. For example, you cannot guarantee that all 10 update files have been downloaded. The client may not be able to get rid of the "semi-Update" application.

The application can be used offline only when you manually set it to "working offline" in Internet Explorer. The application itself cannot control it.

By default, the. config file associated with the program cannot be used (Click here to learn how to use it ).

Your application will not be on the desktop orStartAdd shortcuts to the menu.

Update application blocks

To solve some of the problems mentioned above, Microsoft has created an update Application Block (UAB ). This update block is a library. You can add it to the application so that you can manage the download of the Application Block through HTTP.

Unlike the initial framework implementation, it has the following advantages:

It runs as a local application and can be used at any time without affecting the performance.

Update is a transaction process, that is, all new versions of files must be successfully downloaded before the new version is available.

All application files are listed in the form of a list.

It runs as a fully trusted application and you do not need to adjust the Client Security Policy.

Your application willStartAdd shortcuts to the menu.

On the other hand, there are some shortcomings:

To use an application, you must make major changes to it.

Because bits is used to download application blocks, it cannot run in Windows 98/me, but only in Windows 2000 or later.

It runs as a fully trusted local application, so it almost ignores the security of code access.

Microsoft does not provide support for it.

For more information about UAB, see. NET application Updater component written by Jamie cool. You can also refer to the home of the UAB on gotdotnet. Although UAB does not receive "official" support, there is a forum on www.gotdotnet.com. In any case, UAB comes with complete source code and you can modify it to fix some of the limitations (such as the need for bits and Windows 2000 ).

Clickonce

Obviously, UAB is only a transitional measure, during which Microsoft developed a final solution. This solution is clickonce. Basically, clickonce has all the advantages of UAB, but it has almost no limitations, and some new features are added. In my opinion, one of the main advantages of clickonce is that it restores the security of code access.

Compared with href EXE, clickonce applications have the following advantages:

An update is a transaction (that is, it is either completely executed or not executed at all ).

This application can not only work offline, but also control it to some extent. Some APIs can make the application discover that it is online or offline; it can also control its own update process;

It can be well integrated with Visual Studio. NET, including the ability to generate appropriate additional files and tools to help you find the security permissions required to run the application.

It has a Win32 "bootstraper" executable file that can download required components (or even the. NET Framework itself.

You can download application files as needed or in batches;

It can be found inStartAdd shortcuts to the menu;

Clickonce is a feature of Visual Studio 2005 (previously developed code named "Whidbey") and. NET Framework 2.0. Let's take a look at an example of using "community preview Beta 1" (Framework 2.0.40607.

A clickonce Application

Follow these steps to create a simple clickonce application.

1.

Start Visual Studio 2005.

2.

SelectFileAnd then clickNew project.

3.

Select a language (C # Or Visual Basic. net) and select a Windows application.

4.

Name the projectMyclickonceappClick OK ".

5.

Add a button to the form andTextProperty changedAbout.

6.

Double-click the button. Enter the following code in the code window.

Visual Basic. Net:

     MsgBox("My First ClickOnce Application")

C #:

     MessageBox.Show("My First ClickOnce Application");

PressF5Key to run and test the application.

In Visual Studio 2005, all Windows ApplicationsProject | myclickonceapp PropertiesEach hasPublishPage to control the deployment details:

Figure 1. Configure release settings

Publishing locationIndicates where the application will be deployed. It can be a web server (HTTP) location (as shown in the previous figure), but it can also be a conventional network path.

Install mode and settingsControl Multiple deployment details, such:

Whether the application supports online or offline only.

Application Files: The installation location of a single file.

Prerequisites: Whether the installer must install other components, such as Windows Installer 2.0,. NET Framework 2.0, J # redistributable package, SQL Server 2005 Express, Crystal Reports, and Microsoft Data Access Components 2.8.

Figure 2. Configure prerequisites

Updates: Controls when the application should check for updates and how to provide these updates to the client.

Figure 3. Configuration update

Option: Adjust detailed information, such as the application language,StartMenu shortcut Resource Name, HTML page for Web deployment, and deployment policy ticket.

Figure 4. Configure publish options

Publish versionAdjust the application version number. The version number is automatically added during each deployment.

Publish wizardDifferent publishing options can be set. The wizard can also useBuild | publishMenu call. All clickonce applications must be signed in encrypted mode. This wizard requests an existing key (recommended) or generates a new key.

Figure 5. Sign the application

After running the wizard once, you can clickPublish nowRelease updates. A web page is displayed in our example.

Figure 6. Released applications

This web page contains a script that checks which additional "prerequisite" installation package must be installed before the application is installed. If no prerequisite is available, it is installed when the application is running for the first time.

ClickInstallAfter the link, multiple dialog boxes that may require user intervention will appear (at least the first operation requires user intervention ):

Windows XP SP2 warning

Software License Agreement

Signature authentication is missing

Deployment details

Visual Studio. NET 2005 creates a new web with multiple files and folders for the application.

Figure 7. Deployment folder

The dotnetfx folder contains the reusable. NET Framework (currently a 25 MB executable file ).

By default, Visual Studio adds a version number each time an application is deployed. Each version gets a new folder corresponding to the added version number.

. ApplicationThe file is an HTML page.Publish.htmThe target of the link. It is an XML file that contains information (such as folders corresponding to the current version of the application and the current digital signature.

Publish.htmIs a Web page that not only contains. ApplicationFile Link, and some client scripts can check some versions and display the corresponding information. For example, if your computer does not have. NET Framework,Install myclickonceappDifferent messages are displayed.

Setup.exeIs a Win32 executable file that not only installs applications, but also installs necessary components (such as. NET Framework itself and MDAC 2.8) in the correct order ).

Each application folder contains the application files and configuration files. A list is an XML file that contains the following information:

The exact identity of all application files. This identity contains the file name, version number, region, and processor architecture ("msil" in this example ").

All permissions required by the application.

Digital signature.

Run the application

After the application is downloaded, you can run it instead of downloading it again. In our example, you can click the link to the Web page orStartIn the shortcut menu, start the application. In both casesApplication updatesThe setting in the project option can check whether a new version exists. You can download the new version as needed.

To check the UPDATE function, follow these steps:

1.

Make a visible change to the application, such as changing the button position on the form.

2.

Click the build button again and deploy it.

3.

Run the application and check the download process.

Note: This information is based on Visual Studio. NET Beta 1, which is very important. The new version may have different functions.

Comparison chart
  Href. exe UAB Clickonce

Applications do not require changes

X

 

X

Application Isolation

X

 

X

Fully supported

X

 

X

Low system impact

X

 

X

Keep code access security

X

 

X

Download On-Demand files

X

 

X

List of required files listed in declarative form

 

X

X

List of encrypted signatures

 

 

X

Batch File Download

 

X

X

Offline

(*)

X

X

Transaction Processing Installation

 

X

X

Optimal Performance

 

X

X

Windows 2000 or later

 

X

(**)

Windows Shell Integration

 

X

X

Correct control over the update process

 

X

X

API for working offline and controlling the download process

 

X

X

Automatic Installation of optional packages

 

 

X

(*) User intervention required

(**) It is too early for beta products.

Summary

Clickonce is a very powerful application deployment technology. It is a natural development of the previously used deployment model, providing reliability, security, performance and flexibility for Windows Forms applications with rich client experience.

About the author

Mauro Sant Anna (mas_mauro@hotmail.com) is a regional manager for Microsoft, MCSD, MCSE, developers and trainers. He was the first believer in. Net since it was publicly released on Orlando PDC 2000.

Go to the original English page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.