开发桌面应用程序的时候,经常会因为新增功能需求或修复已知问题,要求客户更新应用程序,为了更好的服务客户,通常会在程序启动时判断版本变更情况,如发现新版本则自动弹出更新对话框,提醒客户更新成最新版本。在.Net体系中采用 AutoUpdater.NET 组件可以非常便捷的实现这一功能。
老规矩从NuGet获取 AutoUpdater.NET 组件:

新建WinForm示例程序,主要代码如下:
- namespace AutoUpdaterWinFormsApp
- {
- using AutoUpdaterDotNET;
-
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void Form1_Load(object sender, EventArgs e)
- {
- AutoUpdater.InstalledVersion = new Version("1.2");
- System.Timers.Timer timer = new System.Timers.Timer
- {
- Interval = 1 * 30 * 1000,
- SynchronizingObject = this
- };
- timer.Elapsed += delegate
- {
- AutoUpdater.Start("https://rbsoft.org/updates/AutoUpdaterTest.xml");
- };
- timer.Start();
- }
- }
- }
xml配置:
- "1.0" encoding="UTF-8"?>
- <item>
- <version>2.0.0.0version>
- <url>https://rbsoft.org/downloads/AutoUpdaterTest.zipurl>
- <changelog>https://github.com/ravibpatel/AutoUpdater.NET/releaseschangelog>
- <mandatory>falsemandatory>
- item>
