Create a Self-Updating WinForms App with the Application Updater Block[1]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

Create a Self-Updating WinForms App with the Application Updater Block

posted on Thursday, June 10, 2004 11:25 AM

During the past couple of weeks, I've been doing some of my first real dotnet WinForms App development.  It's been a fun journey, I'm still learning stuff like crazy.  One of the things I wanted to do was enable the app to be self-updating using the ApplicationUpdater Block from MS.  This took me a considerable effort to get working right, and I thought that the MS samples lacked a step-by-step example.  Duncan Mackenzie has a good blog post here that was a great start, but the examples were VB and it didn't go into the specifics of the Public and Private RSA key stuff, so I thought I'd post this walk through.  I hope it works for you!

Step #1 Install the Application Blocks

Download the Updater Application Block from Microsoft .

Run the MSI Installer.

Step #2 Add the Code and References to Your Project:

Add the following projects to the solution containing your Winforms project :

Microsoft.ApplicationBlocks.ApplicationUpdater
Microsoft.ApplicationBlocks.ApplicationUpdater.Interfaces
Microsoft.ApplicationBlocks.ExceptionManagement
Microsoft.ApplicationBlocks.ExceptionManagement.Interfaces

They should be located in the following folder, if you've accepted the defaults

C:\Program Files\Microsoft Application Blocks for .NET\Updater\Code\CS\Microsoft.ApplicationBlocks.Updater

Reference the following projects from within your Winforms Project

Microsoft.ApplicationBlocks.ApplicationUpdater
Microsoft.ApplicationBlocks.ApplicationUpdater.Interfaces
Microsoft.ApplicationBlocks.ExceptionManagement

Add the following namespaces to your form's .cs file.

using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Threading;
using System.Diagnostics;
using System.IO;
using System.Xml;

Then add the application updater code located here add the application updater code located here to your code.  You'll need to call InitializeAutoUpdate() from your MainForm's Initialize method.

Step #3 Create your Application's Deployment Directory Structure and Configure AppStart.exe

Create a folder for your client installation.  For example purposes, we'll use the following directory:

C:\Program Files\YourApp\1.0.0.0\

Now copy the AppStart.exe and AppStart.exe.config into the root directory like so:

 C:\Program Files\YourApp\AppStart.exe
 C:\Program Files\YourApp\AppStart.exe.config

Note: You can find these two files in the “C:\Program Files\Microsoft Application Blocks for .NET\Updater\Code\CS\Microsoft.ApplicationBlocks.Updater\AppStart\bin\Debug“ directory. 

Step #4 Modify the AppStart.exe.config File

AppStart.exe will launch your application and allow a restart once an update has been downloaded.  It needs to know the directory to use to launch the latest version of your app. 
Modify this config file to match the current version like so:

本文关键:Create a Self-Updating WinForms App with the Application Updater Block
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top