高興啊。。。。。。。。。。。。。下面是所有步驟。研究了一上午終於搞定。
Step 1: Build the application to update<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
In this step we will build the application to auto-update. If you want, you can substitute in your own application here. You can also use the pre-built sample application included in the Samples/SampleApp/SampleApp directory of the zip file. However for the purpose of proving that there isn’t anything special about SampleApp, we’ll walk through its creation.
1. Use Visual Studio .NET to create a new Windows Application project, name it “SampleApp”.
2. Give the form an interesting background color of your choice. We will be using background color to differentiate between versions later.
3. Now let’s add a tiny bit of functionality to this application in the form of a button that opens a form residing in a separate assembly. First add a button to your form. The zip file contains an assembly with a simple Windows Form in it. Add a reference to the Samples/SampleApp/SimpleForm assembly in the zip. Then add two lines of code to your button event handler:
SimpleForm.Form1 F = new SimpleForm.Form1();
F.Show();
4. Switch your build flag to build RELEASE instead of debug. This will allow us to avoid pdb file locking problems later when we build a new version of the application while the original copy is still running.
5. Build and test your application. It should look similar to the Samples/SampleApp/SampleApp in the zip file.
Step 2: Add the .NET Application Updater Component
In this step we will add the .NET Application Updater component to SampleApp.
1. In the components tab of the Visual Studio .NET toolbox, right click and select ‘Customize Toolbox’. Select the ‘.NET Framework Components’ tab. Browse and select the AppUpdater.dll in the AppUpdater project included in the zip. Click OK.
2. An AppUpdater icon should now show up at the bottom of the list of components in the toolbox. Drag and drop the AppUpdater component onto the SampleApp Form. An appUpdater1 instance of the .NET Application Updater component should be instantiated and appear below the form.
Step 3: Configure the .NET Application Updater Component
In this step we will configure the .NET Application Updater component. To do this, select the appUpdater1 component and open its properties. The following section contains a description of each property and what value to set it to. Note that you only need to change the first four properties for this example, for the rest, the defaults are adequate.
AppUpdater Properties – These are the core properties of the .NET Application Updater and will need to be set for this application as follows:
| Property Name
|
Description
|
| AutoFileLoad |
This controls the on-demand download feature described later, for now set this to true. |
| ChangeDetectionMode |
This enum determines how to check for updates. In this example, we will use a server manifest check, so set this value to “ServerManifestCheck”. |
| ShowDefaultUI |
The .NET Application Updater component has a set of simple UI for notifying the user of events such as a new update becoming available or errors during updates. This UI can be replaced with custom application specific UI by disabling the default UI, hooking the appropriate events (ex. OnUpdateComplete) and popping up the custom UI. For this example we will use the default UI, so set this value to true. |
| UpdateUrl |
The UpdateUrl is what determines where the updater looks for updates. In this case we are using a server manifest to check for updates, so this property should be set to the URL of the server manifest. For this example, set it to http://yourWebserver/SampleApp_ServerSetup/UpdateVersion.xml. Replace ‘yourWebserver’ with the name of your Web server. |
Downloader Properties – The AppUpdater component has two sub-components. The first is called the Downloader and controls the download and installation of the component. Below is a description of the properties, but all defaults will work fine for our SampleApp.
| Property Name
|
Description
|
| DownloadRetryAttempts |
If a failure occurs during download (ex the Web server goes down) the downloader will try again a little later. This property controls the number of times the downloader will retry the network request before treating it as a complete application update failure. |
| SecondsBeteweenDownloadRety |
The number of seconds before retrying the network request. |
| UpdateRetryAttempts |
If a serious error occurs during the update process, (ex. The downloader has exceeded the DownloadRetryAttempts), an application update error is generated. By default, the update attempt will stop, but will attempt to resume the next time the application is started (ex… maybe the update Web server was just down for day). This property controls how many times an update will be attempted. If this value is exceeded, the updater aborts the update, resets its state and goes back to checking for updates. |
| ValidateAssemblies |
This controls the level of validation done on downloaded assemblies. See the security section of this paper for more info. |
Poller Properties – The second sub-component of the AppUpdater is the Poller. The Poller controls the update checks. Below is a description of the properties, but all defaults will work fine for our SampleApp.
| Property Name
|
Description
|
| AutoStart |
A Boolean that controls whether or not the Poller should begin polling for updates on application startup or whether it should wait until it is explicitly started programmatically. |
| DownloadOnDetection |
A Boolean that controls whether or not the Poller starts a download of an update immediately after a new update is found, or whether the download must be started explicitly by a call to the DownloadUdpate() method. |
| InitialPollInterval |
The number of seconds after application startup before the first update check is performed. |
| PollInterval |
After the first update check, the PollInterval controls the number of seconds between each subsequent update check. Note: By default this checks every 30 seconds; clearly you will want to reduce the frequency for your application. |
When all is said and done, your property grid should look the following:
<?xml:namespace prefix = v ns = "urn:schemas-microsoft-com:vml" />
The Samples/SampleApp/SampleApp_Complete directory contains a version of the application correctly setup.
Step 4: Build & Deploy V1 of the application to the client
In this step we will build the V1 version of the application and deploy it to the client. The deployment is essentially simulating what the install program for your application will do.
1. In the SampleApp project, open the AssemblyInfo.cs file. Change the AssemblyVersion value from "1.0.*" to “1.0.0.0”. This will cause the built assembly to get marked with a value of “1.0.0.0” instead of the ever increasing value Visual Studio normally assigns.
2. Build the application.
3. Copy the Samples/SampleApp/SampleApp_ClientSetup directory from the zip onto your local machine. It doesn’t matter where you copy it, however the program files directory is the most realistic place to put it since that is where most applications get installed. You’ll notice that SampleApp_ClientSetup directory already has AppStart.exe included. AppStart.config is already set to point into the 1.0.0.0 directory and run SampleApp.exe.
4. Copy the complete SampleApp (Appupdater.dll, SimpleForm.dll & SampleApp.exe) from the release build directory of SampleApp to the SampleApp_ClientSetup/1.0.0.0 directory on your client.
At this point a fully functional version of the application should be “installed” on the client and executable by running AppStart.exe
Step 5: Setup the Web server
In this step we will setup the Web server for use in rolling out application updates. The .NET Application Updater component uses HTTP-DAV to download the application update and thus requires a Web server that supports HTTP-DAV. IIS 5.0 that comes with Windows 2000 and newer operating systems support HTTP-DAV.
1.