C#使用 AutoUpdater.NET 实现程序自动更新

写在前面

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

老规矩从NuGet获取 AutoUpdater.NET 组件:

参考官方示例

代码实现

新建WinForm示例程序,主要代码如下:

cs 复制代码
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配置:

XML 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<item>
	<version>2.0.0.0</version>
	<url>https://rbsoft.org/downloads/AutoUpdaterTest.zip</url>
	<changelog>https://github.com/ravibpatel/AutoUpdater.NET/releases</changelog>
	<mandatory>false</mandatory>
</item>

调用示例

相关推荐
Morpheon13 分钟前
R语言非结构化文本挖掘入门指南
开发语言·r语言
董先生_ad986ad25 分钟前
MVVM模式中,BaseViewModel 的 IsBusy 属性的作用
c#
CPETW1 小时前
同旺科技 USB TO SPI / I2C适配器(专业版)--EEPROM读写——C
c语言·开发语言·科技·stm32·单片机·嵌入式硬件·电子
代码中の快捷键1 小时前
如何实现一个登录功能?
java·开发语言
虾球xz1 小时前
CppCon 2015 学习:C++ devirtualization in clang
开发语言·c++·学习
czfeixiang1 小时前
专注于PLC数据采集MES交互解决方案
mcu·.net·mes
看到我,请让我去学习2 小时前
C++核心编程(动态类型转换,STL,Lanmda)
c语言·开发语言·c++·stl
conkl2 小时前
Apache网页优化实战指南 - 让网站加载速度提升
linux·运维·服务器·开发语言·阿里云·apache
追逐时光者2 小时前
Visual Studio 2022 中的 EF Core 反向工程和模型可视化扩展插件
.net·visual studio
onlooker66662 小时前
Go语言底层(五): 深入浅出Go语言的ants协程池
开发语言·后端·golang