智能部署与更新
This demonstration shows how to publish a ClickOnce application using the integrated tools in the Visual Studio 2005 IDE and then how to deploy updates to the same application. The demonstration also shows how an installed ClickOnce application is integrated into the Windows shell.
Task 1: 新建一个工程windows窗体
Task 2:应用发布向导
- Select the Build | Publish ClickOnce_Hello menu command.
- This launches the Publish Wizard. This provides the most direct method for configuring and publishing an application for ClickOnce deployment.
- Note that the Publish Wizard is also accessible from the context menu in Solution Explorer, as well as from the Publish pane of the Project Designer. Later in this demonstration, you will explore the Publish pane in more detail.
- In the Publish Wizard, in the Where do you want to publish the application? page, for Specify the location to publish this application, confirm that the value is "http://localhost/ClickOnce_Hello".
- By default, the publish location is based on the name of the main application. Also, by default, the application is published to a Web site. Other location options include an FTP site, a disk location, or network share. You could also publish to a remote Web site. Publishing to a Web site requires that the target IIS is configured to use Front Page Server Extensions.
- Click Next.
- In the Will the application be available offline? page, explain the two installation mode options. The default setting, Yes, this application is available online or offline, provides that the application will be installed on the user's local machine and will have both a shortcut menu and a presence in the Add or Remove Programs list. Use this default selection.
- The other option, No, this application is only available online, provides that the application will launch directly from the publish Web page and will NOT be integrated in the Windows shell.
- Choose “Yes, this application is available online or offline.” Click Next.
- In the Summary page, note that the text summarizes the location and type of ClickOnce deployment you are publishing.
- Click Finish.
- The Output window will display the compilation and publication progress step-by-step while the status bar of the Visual Studio 2005 IDE tracks overall progress. The publishing engine creates the necessary files for the deployment: including the application binary files, the deployment and application manifests, a bootstrapper program, and an HTML page: and stores them in a local project directory. When publishing to a Web site for the first time, the publishing engine then creates a new Web application on the target server (if it doesn't already exist) and copies the deployment files from the project directory to the virtual directory. When publishing has completed, the newly created publish.htm page launches automatically in an instance of Internet Explorer.
Task 3: 安装一次性部署 智能客户端程序
In Internet Explorer, in the ClickOnce_Hello page, click the Install button. This launches the Application Install dialog box.
- The Application Install dialog box notifies the user that the application is from an unknown software publisher. The message also indicates that the application may require unrestricted access to the user's machine. Optionally, you can click More Information to display more information about machine access and publishers.
- In the Application Install dialog box, click Install.
- The ClickOnce client service installs the application on the local machine and, when complete, launches the newly installed application.
- In Hello ClickOnce, the displayed deployment information indicates that this is a ClickOnce-deployed application. The Running version and Updated version numbers specify the version of the deployment. Update location identifies the deployment manifest (identified by the .application file extension).
- Select the Help | About menu command.
- This demonstrates that the deployment version is different than the version of the application assembly.
- Close the application.
- Navigate to Start | All Programs | Northwind Traders | ClickOnce_Hello.
- This shows that the application has an offline presence.
- Close the application.
Task 4: Configure ClickOnce Settings
- In Visual Studio, under the ClickOnce_Hello project, double-click the Properties folder.
- This opens the Project Designer.
- In the Project Designer, click the Publish tab.
- In the Publish pane, review the available settings options.
- The attributes you specified in the Publish Wizard are available here (Publishing location, Install Mode). Explain that you can specify a documentation URL or an installation URL (if it differs from the publishing location). Explain Publish Version, which controls the version of the deployment and which can be set manually or incremented automatically (the default). (The Publish Version displays in the deployment information control of the demonstration application.)
- Click Options.
- Review the ClickOnce deployment property settings available in the Publish Options dialog box. The Publish Language value, for example, specifies the language used for the display prompts presented to users when they install a ClickOnce application (not the language of the underlying application or the publish.htm page).
- Uncheck “Open deployment web page after publishing.”
- This property controls whether or not the publish.htm page opens automatically every time you publish a ClickOnce application from the Visual Studio 2005 IDE. The publish.htm file itself is created only once: the first time the application is published; this means that after this page is created you can use any HTML editor you like to customize the look and feel of the page without running the risk that it will be overwritten when you publish updates to the deployment.
- Click OK.
- In the Publish pane, click Updates.
- The Application Updates dialog box allows you to configure the deployment for different types of update scenarios. This includes whether the application should check for updates before it starts, or while the application is running. You can also control how frequently the application should check for updates, and whether or not updates are mandatory. You can even disable automated update checking entirely by unchecking The application should check for updates; an appropriate choice in a situation where you want to control update checks programmatically.
- (Of course, configuring update checking is not available for applications configured to only run online, in which case they always run the most recent version of the application.)
- Click OK.
- In the Publish pane, click Prerequisites.
- In the Prerequisites dialog box, note that the .NET Framework 2.0 component is selected. By default, the publishing engine creates a setup program containing this component. Any other redistribution packages you select in this dialog box are included in the bootstrapper program deployed with the application (you can also add your own redistribution packages to this list). If you are working in a managed network where you know for certain that all of the application prerequisites are already installed on users machines, you can uncheck Create setup program to install prerequisite components to exclude the setup program from the deployment.
- You can also use this dialog box to specify a separate download location for prerequisites. This makes sense if you are in a corporate environment where a number of different applications require the same prerequisites; installing them from a common location saves network bandwidth and storage space and makes updating the prerequisite setup program easier to manage.
- Click OK.
- In the Publish pane, click Application Files.
- In the Application Files dialog, review the different files included in the deployment. In this demonstration, this includes both the primary application assembly (ClickOnce_Hello.exe and ClickOnce_Hello.exe.config), but also the application icon file (Earth.ico) and the assembly for the custom user control (SmartClient.controls.dll).
- In deployment scenarios that include large files, you can use this dialog box to mark non-essential files as optional (Help files, for example). Do this by creating a new project group and assigning files to the group as necessary. You could then control how and when these files are later downloaded programmatically using the ClickOnce APIs.
- You can also explicitly exclude files from the deployment. In this case, you could change the Type of the Hello_ClickOnce.pdb file or SmartClient.controls.pdb file from (Default) to Exclude.
- Click OK.
Task 5: Deploy and Install Updated Application
- Optional: alter the appearance of the application.
- This will help signify that the application has been changed and needs to have the update published via ClickOnce. This can be as trivial as changing the background color of the main form. However, this is not a requirement for publishing a new version of the deployment.
- In the Publish pane, note that the Publish pane has buttons for invoking the Publish Wizard and for publishing directly using Publish Now.
- Click Publish Now.
- Navigate to Start | All Programs | Northwind Traders | ClickOnce_Hello.
- When you start the application, a status dialog displays. This is rendered by the ClickOnce client service (dfsvc.exe, which you can locate as a running process in Task Manager). This dialog appears while this service reads the local copy of the deployment manifest to determine if an update check is necessary. It then communicates with the updated deployment manifest at the publishing location and learns that an update is indeed available. It then displays an Update Available dialog box to the user.
- Because in this case the update is not mandatory, users have the option of installing the update or skipping the update. For a mandatory update, the ClickOnce service does not prompt the user and installs the new version automatically.
- In the Update Available dialog box, click Ok.
- The ClickOnce service installs the new version of the application and then launches it.
Task 5: Roll the Application Back
- Navigate to Start | Control Panel | Add or Remove Programs.
- In Add or Remove Programs, select ClickOnce_Hello.
- Click Change or Remove.
In the ClickOnce_Hello Maintenance dialog box, you have the choice of removing the application entirely or rolling it back to the previous version. Note that ClickOnce only supports rollback to the immediately preceding version.
- Select Restore the application to its previous state.
- Navigate to Start | All Programs | Northwind Traders | ClickOnce_Hello.
The version will have changed back to its previous version and displays 1.0.0.0.
Task 7: Uninstall the Application
- Navigate to Start | Control Panel | Add or Remove Programs.
- In Add or Remove Programs, select Northwind Traders ClickOnce_Hello.
- Click Click here for support information.
The Support Info dialog box displays the version and update location of the application.
- Click Close.
- Click Change or Remove.
- Select Remove the application from this computer and then click OK.
- Optional: after uninstall is complete, show that the shortcut to the application has been removed from the start menu.
- Close Visual Studio without saving changes.