分享
 
 
 

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

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

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

Create a Self-Updating WinForms App with the Application Updater Block 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.0Now 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:

<appStart>

<ClientApplicationInfo>

<appFolderName>C:\Program Files\YourApp\1.0.0.0</appFolderName>

<appExeName>YourAppName.exe</appExeName>

<installedVersion>1.0.0.0</installedVersion>

<lastUpdated>2004-06-10T15:33:17.3745836-04:00</lastUpdated>

</ClientApplicationInfo>

</appStart>

Step #5: Create Your Public and Private Keys

Run the ManifestUtility 'C:\Program Files\Microsoft Application Blocks for .NET\Updater\Code\CS\Microsoft.ApplicationBlocks.Updater\ManifestUtility\bin\Debug\ManifestUtility.exe'

Choose “File..Generate Keys” You will be prompted to save the following keys: PublicKey.xml and PrivateKey.xml You'll be using these keys in the next steps.

From what I can tell it's best to create these keys once, because you'll need to reference these RSA public and private keys in a couple of places. You'll want to keep your keys in a safe place, because you'll need them when pushing new updates.

Step #6 Create Your IIS Virtual Directory

Create a directory on your WebServer to house your updates. You will end up with two things in this directory 1) a ServerManifest.xml file which will contain the latest version information, and 2) your new application directory. Within this directory, create a directory to house your new application version. So, for our example, we'll create the directories, C:\Inetpub\AppUpdates and C:\Inetpub\AppUpdates\1.0.0.1

Use IIS Manager to create a virtual directory pointing to this physical directory. Remember your URL, as you will need it in an upcoming step. You will have to enable directory browsing for this virtual directory.

Step #7. Configure Your Version 1.0.0.0 App.config File

Here, we'll need to add a few things. First, we need to add a configSections element to define our appUpdater section:

<configSections>

<section name='appUpdater' type='Microsoft.ApplicationBlocks.ApplicationUpdater.UpdaterSectionHandler,Microsoft.ApplicationBlocks.ApplicationUpdater' />

</configSections>

Next we need to add the Version key to our appsettings key, we're first going to set our local versoin to 1.0.0.0, so that we can test the auto-update to version 1.0.0.1

<appSettings>

<add key='VERSION' value='1.0.0.0' />

</appSettings>

Finally, add the appUpdater section to your config file. I've put brackets where you need to edit the values. You can just copy the <RSAKeyValue> element from the PublicKey.xml file that you created in the previous step.

The <xmlFile> elements should point to your Virtual directory's URL that you created in step #6.

<appUpdater>

<UpdaterConfiguration>

<polling type='Seconds' value='120' />

<logListener logPath='C:\Program Files\YourApp\UpdaterLog.txt' />

<downloader type='Microsoft.ApplicationBlocks.ApplicationUpdater.Downloaders.BITSDownloader'

assembly='Microsoft.ApplicationBlocks.ApplicationUpdater,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'/>

<validator type='Microsoft.ApplicationBlocks.ApplicationUpdater.Validators.RSAValidator' assembly='Microsoft.ApplicationBlocks.ApplicationUpdater,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null'>

<key>

<RSAKeyValue>

<Modulus>[YOUR MODULUS KEY]</Modulus>

<Exponent>[YOUR EXPONENET]</Exponent>

</RSAKeyValue>

</key>

</validator>

<application name='[YOUR APP NAME]' useValidation='true'>

<client>

<baseDir>C:\Program Files\YourApp</baseDir>

<xmlFile>C:\Program Files\YourApp\AppStart.exe.config</xmlFile>

<tempDir>C:\Program Files\YourApp\temp</tempDir>

</client>

<server>

<xmlFile>http://[YOUR URL]/ServerManifest.xml</xmlFile>

<xmlFileDest>C:\Program Files\YourApp\ServerManifest.xml</xmlFileDest>

<maxWaitXmlFile>60000</maxWaitXmlFile>

</server>

</application>

</UpdaterConfiguration>

</appUpdater>

Step #8 Deploy Version 1.0.0.0

Version your app. You do this by setting the version attribute of your app's AssemblyInfo.cs file.

[assembly: AssemblyVersion('1.0.0.0')]

Build the Application and copy version 1.0.0.0 to your program file's 1.0.0.0 directory. “C:\Program Files\YourApp\1.0.0.0“

At this point, you should be able to run AppStart.exe. The update process should fail, since we haven't deployed the ServerManifest XML file which tells our app that there's a new version available. You can inspect the log files that should be created in your C:\Program Files\YourApp\ directory.

Step #9 Buld Version 1.0.0.1

This is the fun part. First, create revision 1.0.0.1 by updating your application's AssemblyInfo.cs and App.config files to reflect the new version. Build your application, and copy the files to the web server directory created in step #6.

Step #10 Create Your Server Manifest File

This should be the last step. Any changes you make to the .config files from this point on will require repeating this step. To do this:

Launch the ManifestUtility program again. Choose the 1.0.0.1 directory from the “Update files folder“ chooser. Enter the URL of the update location. Enter version 1.0.0.1 Open your PrivateKey.xml file created earlier. Choose the validator class “Microsoft.ApplicationBlocks.ApplicationUpdater.Validators.RSAValidator” Click CreateManifest, and save the ServerManifest.xml file to your virtual server directory.That's it! Pheeew! Run your AppStart.exe from your C:\Program Files\YourApp\ directory. Your app should launch, and you should now be prompted that “A new version is available” when you launch your application. The new app should be downloaded into your C:\Program Files\YourApp\1.0.0.1 directory, and the app should re-start itself. If you have problems, be sure to check the log files that are created during the process. They can be very helpful in tracking down bugs.

-Brendan

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有