Last time we talked about how to deploy an application project using ClickOnce Technology in the most basic way. In this article, we will learn how to enable automatic update for the application.
We still learn through instances.
Step 1: Create an application project on your own. Go to the console, WPF, or WinForm. We will focus on releasing applications. For example:
For better demonstration, we can display the current version number in the window. Here I am a WinForm project, so I will use a Label control to display the current version.
Note ,. Therefore, use the ApplicationDeployment class (located in the namespace of System. Deployment. Application, in the assembly System. Deployment. dll, if there is no reference, reference it ). The Static Property CurrentDeployment can be used to obtain an ApplicationDeployment object related to the currently deployed application. Then, you can obtain the current version number from the CurrentVersion attribute of ApplicationDeployment. The Code is as follows. As for where to write it, you can think about it as a basic task.
Okay, OK. Now we can release this application, because we want it to be automatically updated, and we will release it to IIS or other servers. In addition, to enable the update check function, as mentioned in the previous section, the operation is also very simple.
In the Project Properties window, switch to the release tab and click Update... "Button to enable Update check. As for how to update, you can do it by default, and there is no need to change it.
Then, make sure that the configuration is complete. And then publish it to the server.
Step 2: Enter the address in the browser to install and run the application, as shown in. Note that the current version is 1.0.0.0.
Step 3: Close the application and return to VS. Let's change the program to simulate the upgrade. For example, I add a button in the window, for example.
Step 4: Open
Click the "Publish now" button below.
Step 5: after the application is released successfully, run the application you just installed again from "start". The update prompt dialog box is displayed.
Click OK to automatically download and install the update. At this time, we can see that the version is 1.0.0.1.