Github
AutoUpdater.NET
目錄
一、IIS部署 更新站點
二、創建Winform
一、IIS部署 更新站點
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
<?xml version='1.0' encoding="UTF-8"?>
<item><!--在版本標記之間提供應用程序的最新版本。版本必須為X.X.X.X格式。--><version>1.0.0.2</version><!--在url標簽之間提供最新版本安裝程序文件或zip文件的url。自動更新。NET下載這里提供的文件,并在用戶按下Update按鈕時安裝它。--><url>http://127.0.0.1/Downloads/fr.zip</url><!--在changelog標記之間提供應用程序更改日志的URL。如果你不提供變更日志的URL,那么更新對話框將不會顯示變更日志。--><changelog>http://127.0.0.1/Updates/UpdateLog.html</changelog><!--如果你不想讓用戶跳過這個版本,可以將其設置為true。這將忽略“稍后提醒”和“跳過”選項,并在更新對話框中隱藏“稍后提醒”和“跳過”按鈕。--><!--mandatory mode="2">true</mandatory --><!--可以在強制元素上提供minVersion屬性。當您提供該選項時,只有當安裝的應用程序版本小于您在這里指定的最小版本時才會觸發強制選項。--><!--mandatory minVersion="1.2.0.0">true</mandatory --><!--args(可選):您可以在這個標記之間為安裝程序提供命令行參數。您可以在命令行參數中包含%path%,它將被當前正在執行的應用程序所在目錄的path所取代。--><!--mandatory args="xxxxx">false</mandatory --><!--提供更新文件的校驗和。如果你做這個autotoupater。NET將在執行更新過程之前比較下載文件的校驗和,以檢查文件的完整性。您可以在校驗和標記中提供algorithm屬性,以指定應該使用哪個算法來生成下載文件的校驗和。目前支持MD5、SHA1、SHA256、SHA384和SHA512。--><!--checksum algorithm="MD5">Update file Checksum</checksum -->
</item>
二、創建Winform
netcore 3.1 + Winform?
nuget安裝包
Autoupdater.NET.Official? ? ? ? --版本1.8.0
?2.1創建MainForm
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{/// <summary>/// 自動更新/// </summary>/// <param name="serverPath"></param>/// <param name="synchronizeInvoke"></param>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();#endregionAutoUpdater.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中的版本則觸發CheckForUpdateEventAutoUpdater.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);}}};}}}
?2.2打包
winfrom生成文件添加到壓縮文件 fr.zip,復制到IIS站點Downloads目錄下
?
2.3更新
?手動更新
?自動更新從版本1.0.0.1 更新到1.0.0.2?