WPF Core發佈有個文件發佈選項:生成單個文件,自動升級就比較方便了。 一、下載新版本程式,保存為...Exe~,並運行 二、替換老版本並運行 ...
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;
}