AutoUpdater.NET
目录
IIS默认站点目录下创建 目录 Downloads、Updates
Updates目录创建文件 UpdateLog.html、AutoUpdaterStarter.xml
UpdateLog.html:
- <html>
- <body>
- <h1>
- UpDate
- h1>
- body>
-
- html>
AutoUpdaterStarter.xml:
url节点 为下载更新的地址 http://127.0.0.1/Downloads/fr.zip
- "UTF-8"?>
- <item>
-
- <version>1.0.0.2version>
-
-
- <url>http://127.0.0.1/Downloads/fr.zipurl>
-
-
- <changelog>http://127.0.0.1/Updates/UpdateLog.htmlchangelog>
-
-
-
-
-
-
-
-
-
-
-
-
- item>

netcore 3.1 + Winform
nuget安装包
Autoupdater.NET.Official --版本1.8.0
http://127.0.0.1/Updates/AutoUpdaterStarter.xml 为IIS站点更新配置文件
检查版本
- public partial class MainForm : Form
- {
- public MainForm()
- {
- InitializeComponent();
-
- Assembly assembly = Assembly.GetEntryAssembly();
- label1.Text = $"{assembly.GetName().Version}";//显示版本号
-
- AutoUpdatorHelper.Start("http://127.0.0.1/Updates/AutoUpdaterStarter.xml", this);
- }
-
- private void button1_Click(object sender, EventArgs e)
- {
- AutoUpdater.Start("http://127.0.0.1/Updates/AutoUpdaterStarter.xml");//手动更新
- }
-
- public class AutoUpdatorHelper
- {
- ///
- /// 自动更新
- ///
- ///
- ///
- public static void Start(string serverPath, ISynchronizeInvoke synchronizeInvoke)
- {
- #region 每隔60秒检查一次更新(判断依据是AssemblyInfo中的版本和xml文件的版本是否一致,如果服务器xml文件的版本大于AssemblyInfo中的版本则触发CheckForUpdateEvent)
- System.Timers.Timer timer = new System.Timers.Timer
- {
- Interval = 60 * 1000,//毫秒
- SynchronizingObject = synchronizeInvoke
- };
- timer.Elapsed += (object sender, ElapsedEventArgs e) =>
- {
- AutoUpdater.Start(serverPath, Assembly.GetExecutingAssembly());
- };
- timer.Start();
- #endregion
-
- AutoUpdater.LetUserSelectRemindLater = true;
- AutoUpdater.RemindLaterTimeSpan = RemindLaterFormat.Minutes;
- AutoUpdater.RemindLaterAt = 1;
-
- //若您不想在更新表单上显示“跳过”按钮,那个么只需在上面的代码中添加以下行即可。
- AutoUpdater.ShowSkipButton = false;
-
- //如果要同步检查更新,请在启动更新之前将Synchronous设置为true,如下所示。
- AutoUpdater.Synchronous = true;
-
- //若你们不想在更新表单上显示“以后提醒”按钮,那个么只需在上面的代码中添加以下一行即可。
- AutoUpdater.ShowRemindLaterButton = false;
-
- //如果要忽略先前设置的“以后提醒”和“跳过”设置,则可以将“强制”属性设置为true。它还将隐藏“跳过”和“稍后提醒”按钮。如果在代码中将强制设置为true,那么XML文件中的强制值将被忽略。
- AutoUpdater.Mandatory = false;
-
- //您可以通过添加以下代码来打开错误报告。如果执行此自动更新程序。NET将显示错误消息,如果没有可用的更新或无法从web服务器获取XML文件。
- AutoUpdater.ReportErrors = true;
-
- //如果服务器xml文件的版本大于AssemblyInfo中的版本则触发CheckForUpdateEvent
- AutoUpdater.CheckForUpdateEvent += (args) =>
- {
- if (args.Error == null)
- {
- //检测到有可用的更新
- if (args.IsUpdateAvailable)
- {
- DialogResult dialogResult;
- if (args.Mandatory.Value)
- {
- dialogResult =
- MessageBox.Show(
- $@"当前有一个新版本{args.CurrentVersion}可用.你正在使用版本{args.InstalledVersion}.点击确认开始更新", @"更新可用",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- }
- else
- {
- dialogResult =
- MessageBox.Show(
- $@"当前有一个新版本{args.CurrentVersion}可用.你正在使用版本{args.InstalledVersion}.确认要更新吗?", @"更新可用",
- MessageBoxButtons.YesNo,
- MessageBoxIcon.Information);
- }
-
- if (dialogResult.Equals(DialogResult.Yes) || dialogResult.Equals(DialogResult.OK))
- {
- try
- {
- //触发更新下载
- if (AutoUpdater.DownloadUpdate(args))
- {
- Application.Exit();
- }
- }
- catch (Exception exception)
- {
- MessageBox.Show(exception.Message, exception.GetType().ToString(), MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- }
- }
- else
- {
- MessageBox.Show(
- $@"当前为最新新版本", @"更新可用",
- MessageBoxButtons.OK,
- MessageBoxIcon.Information);
- }
- }
- else
- {
- if (args.Error is WebException)
- {
- MessageBox.Show(
- @"连接更新服务器失败,请检查网络连接.",
- @"更新检查失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- MessageBox.Show(args.Error.Message,
- args.Error.GetType().ToString(), MessageBoxButtons.OK,
- MessageBoxIcon.Error);
- }
- }
- };
- }
- }
- }
winfrom生成文件添加到压缩文件 fr.zip,复制到IIS站点Downloads目录下


手动更新

自动更新从版本1.0.0.1 更新到1.0.0.2 