WPF Core發布有個檔案發布選項:生成單個檔案,自動升級就比較方便了,
一、下載新版本程式,保存為...Exe~,并運行
Process currentProcess = Process.GetCurrentProcess();
File.WriteAllBytes(currentProcess.MainModule.FileName + "~", buffer);
Process p = new Process();
p.StartInfo.FileName = Path.Combine(pathDesktop, filename);
p.StartInfo.UseShellExecute = false;
p.Start();
二、替換老版本并運行
if (currentProcess.MainModule.FileName.EndsWith("~"))
{
File.Copy(currentProcess.MainModule.FileName, currentProcess.MainModule.FileName.TrimEnd('~'), true);
Process p = new Process();
p.StartInfo.FileName = currentProcess.MainModule.FileName.TrimEnd('~');
p.StartInfo.UseShellExecute = false;
p.Start();
return;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/2981.html
標籤:WPF
