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>

调用示例

相关推荐
国思RDIF框架2 天前
RDIFramework.NET CS 敏捷开发框架 V6.3 版本重磅发布!.NET8+Framework双引擎,性能升级全维度进化
后端·.net
晨星shine3 天前
GC、Dispose、Unmanaged Resource 和 Managed Resource
后端·c#
用户298698530143 天前
.NET 文档自动化:Spire.Doc 设置奇偶页页眉/页脚的最佳实践
后端·c#·.net
用户3667462526743 天前
接口文档汇总 - 2.设备状态管理
c#
用户3667462526743 天前
接口文档汇总 - 3.PLC通信管理
c#
Ray Liang4 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
赵榕4 天前
ClaimsPrincipal序列化为Json的正确姿势
.net
追逐时光者5 天前
一款使用 C# 编写专为 Windows 11 打造的文件资源管理器增强工具!
后端·.net