
CheckUpdate.Net 是一个轻量级的 .NET 客户端自动更新框架,适用于 C/S 架构的桌面应用程序。
它通过访问远程服务器(目前基于 七牛云存储)获取更新信息,并下载新版本文件进行更新。相比传统的 IIS 部署方式,利用七牛云 CDN 可显著提升下载速度,且提供每月 10GB 免费流量。
该项目最初是为了解决小型项目中无合适自动更新组件的问题而开发,兼容 .NET Framework 2.0+,适合 Windows XP 及以上系统部署。
✅ 支持单个或多个文件更新 ✅ 自动比对本地与服务端文件 MD5,避免重复下载 ✅ 支持更新更新程序本身 ✅ 利用七牛云 CDN 加速下载 ✅ 提供 WinForm 和 WPF 集成方案 ✅ 弹窗提示更新内容,支持强制更新逻辑
CheckUpdate.Net 的工作流程如下:
UpdateFile.xml 文件。文件名 | 作用 |
|---|---|
UpdateFileClient.exe | 更新主程序 |
UpdateFileCommon.dll | 核心逻辑封装 |
UpdateFile.xml | 更新配置清单 |
UpdateFileClient.exe.config | 配置文件(可选) |
使用 UpdateFileServerToQiNiu.exe 工具上传并管理更新包,依赖 七牛云对象存储。
Access-Control-Allow-Methods: *,以支持跨域请求。UpdateFileServerToQiNiu.exe,填写七牛云配置。UpdateFile.xml。UpdateFileClient.exeUpdateFile.xmlUpdateFileCommon.dllUpdateFileClient.exe.config⚠️ 注意:如果主程序使用
.NET Framework 4.0+,需保留 config 文件;如使用.NET 2.0,请删除该文件。
<UpdateConfig>
<Version>1</Version> <!-- 当前版本 -->
<ReleaseNote>修复了若干BUG</ReleaseNote> <!-- 更新日志 -->
<IsMustUpdate>true</IsMustUpdate> <!-- 是否强制更新 -->
<Files>
<File Name="MainApp.exe" Md5="xxx" />
<File Name="Library.dll" Md5="yyy" />
</Files>
</UpdateConfig>在主程序中添加以下代码,用于检测临时目录中的新版更新器:
using UpdateFileCommon;
// 检查是否有新版本更新器,若有则剪切到主目录
VersionHelper.CutNewUpdateEXE();using System;
using System.Windows.Forms;
using System.Xml;
namespaceYourAppNamespace
{
staticclassProgram
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// 检查并更新更新器
VersionHelper.CutNewUpdateEXE();
// 检查是否需要下载安装包
if (!VersionHelper.GetNewVersionToDownloadSetup())
{
// 检查是否需要更新
if (VersionHelper.IsRequiredUpdate())
{
string xmlPath = AppDomain.CurrentDomain.BaseDirectory + "UpdateFile.xml";
if (File.Exists(xmlPath))
{
XmlDocument doc = new XmlDocument();
doc.Load(VersionHelper.GetLoaclServerConfigURL(xmlPath));
var releaseNote = VersionHelper.GetServiceReleaseNote(doc);
var isMustUpdate = VersionHelper.GetServiceIsMustUpdate(doc);
PromptingForm form = new PromptingForm(releaseNote, isMustUpdate);
form.NextShowEvent += () => {
// 点击“下次提醒”执行的操作
};
Application.Run(form);
return;
}
}
}
// 正常启动主界面
Application.Run(new LoginView());
}
}
}WPF 项目需手动添加 Program.cs 并设置为主启动类:
[STAThread]
public static void Main()
{
VersionHelper.CutNewUpdateEXE();
if (!VersionHelper.GetNewVersionToDownloadSetup())
{
if (VersionHelper.IsRequiredUpdate())
{
string xmlPath = AppDomain.CurrentDomain.BaseDirectory + "UpdateFile.xml";
if (File.Exists(xmlPath))
{
XmlDocument doc = new XmlDocument();
doc.Load(VersionHelper.GetLoaclServerConfigURL(xmlPath));
var releaseNote = VersionHelper.GetServiceReleaseNote(doc);
var isMustUpdate = VersionHelper.GetServiceIsMustUpdate(doc);
PromptingForm form = new PromptingForm(releaseNote, isMustUpdate);
form.NextShowEvent += delegate { /* 处理点击事件 */ };
form.ShowDialog();
}
}
}
// 启动主窗口
App app = new App();
app.InitializeComponent();
app.Run(new MainWindow());
}Gitee: https://gitee.com/xcong/CheckUpdate.Net