我该如何开发Windows应用程序,使其像Firefox、Skype等应用一样,在客户端机器上自动更新?
有没有简单的方法或任何开源库可以帮助我只需遵循一些步骤或几行代码就能完成?
我该如何开发Windows应用程序,使其像Firefox、Skype等应用一样,在客户端机器上自动更新?
有没有简单的方法或任何开源库可以帮助我只需遵循一些步骤或几行代码就能完成?
最受欢迎的框架包括:
我从this article中获取了这些链接。它更详细地介绍了每个框架的优缺点。
使用MD5-Update非常容易,只需要在应用程序中添加5行代码,无需对应用程序进行任何配置,只需添加库并发布文件即可。
1. 您需要一个配备PHP的Web服务器来发布您的文件,请包含updt.exe。
2. 添加index.php以制作更新文件列表。Github存储库中提供了此代码https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip或者使用此代码创建新的应用程序。
<?php
$_dat = array();
$_dir=new RecursiveDirectoryIterator(".");
foreach (new RecursiveIteratorIterator($_dir) as $_itm) {
$_fil = str_replace(".".DIRECTORY_SEPARATOR, "", $_itm);
if(!is_dir($_fil) && $_fil != "index.php"){
$_dat[]=array('StrFil' => "$_fil", 'StrMd5' => strtoupper(md5_file($_fil)), 'lonSiz' => filesize($_fil));
}
}
echo json_encode($_dat, JSON_UNESCAPED_UNICODE);
?>
3. 将Nuget仓库添加到您的项目中
PM> Install-Package MD5.Update
4. 调用库在您的应用程序启动时,使用您的更新文件夹 URL 调用库,更新所有文件并在 updt 文件夹中下载新应用程序,以替换您的应用程序需要 updt.exe。
string strUrl = "http://yourdomain.com/app/";
if (MD5Update.MD5Update.Check(strUrl, true))
{
Process.Start(AppDomain.CurrentDomain.BaseDirectory + @"updt.exe", AppDomain.CurrentDomain.FriendlyName + " " + Process.GetCurrentProcess().ProcessName);
Application.Exit();
}
5. updt.exe 是用来将当前应用程序替换为新的应用程序updt文件夹中的应用程序。可以在github代码库 https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip 上找到该工具,也可以使用此代码创建新的应用程序。
try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
List<string> lisArg = Environment.GetCommandLineArgs().ToList();
if (lisArg.Count < 2)
{
MessageBox.Show("Please provide App Excutable Name and Procees name");
Application.Exit();
return;
}
string strAppName = lisArg[1];
string strAppProcees = lisArg[2];
Process[] lisPro = Process.GetProcessesByName(strAppProcees);
foreach (Process Pro in lisPro)
{
if (Pro.Id != Process.GetCurrentProcess().Id)
{
Pro.Kill();
Thread.Sleep(1000);
}
}
string strAppMain = AppDomain.CurrentDomain.BaseDirectory + strAppName;
string strAppUpdate = AppDomain.CurrentDomain.BaseDirectory + @"updt\" + strAppName;
if (!File.Exists(strAppMain))
{
MessageBox.Show("App Excutable dosent exists");
Application.Exit();
return;
}
if (!File.Exists(strAppUpdate))
{
MessageBox.Show("App Excutable Updated dosent exists");
Application.Exit();
return;
}
File.Copy(strAppUpdate, strAppMain, true);
long fileSize = 0;
FileInfo currentFile = new FileInfo(strAppMain);
while (fileSize < currentFile.Length)
{
fileSize = currentFile.Length;
Thread.Sleep(1000);
currentFile.Refresh();
}
Process.Start(strAppMain);
}
catch (Exception Ex)
{
MessageBox.Show("An error ocurred");
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"updt_" + DateTime.Now.ToString("yyyyMMddTHHmmss") + " .txt", Ex.ToString());
Application.Exit();
}
微软的Ent Lib中还有更新块。
System Center 2012 Configuration Manager 怎么样?
虽然 ClickOnce 简单易用,而且在 .NET 5 中得到了复兴,但它仍然有很多限制。因此,我发现现在有更好的选择:您可以将应用程序打包成 MSIX 捆绑包或软件包,并使用 Windows 10 中提供的 AppInstaller 机制进行应用程序交付。
我在这个 答案 中介绍了我对这个主题的研究结果。