【发布时间】:2011-01-22 18:13:33
【问题描述】:
如何开发我的 Windows 应用程序,使其能够在客户端计算机上自动更新,例如 Firefox、Skype 等?
是否有任何简单的方法或任何开源库可以帮助我按照一些步骤或几行代码来完成它?
【问题讨论】:
标签: c# auto-update
如何开发我的 Windows 应用程序,使其能够在客户端计算机上自动更新,例如 Firefox、Skype 等?
是否有任何简单的方法或任何开源库可以帮助我按照一些步骤或几行代码来完成它?
【问题讨论】:
标签: c# auto-update
ClickOnce 是您要搜索的内容。
您可能还会发现这些 SO 问题很有趣(提供了一些不同的解决方案):
【讨论】:
【讨论】:
在 Ent Lib 中还有 msft 的更新块。
【讨论】:
最流行的框架是:
我从this article 获取了这些链接。它详细介绍了每个框架的优缺点。
【讨论】:
使用 MD5-Update it easy 只需要在你的应用程序中添加 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();
}
【讨论】:
System Center 2012 配置管理器怎么样?
【讨论】:
虽然 ClickOnce 很简单,并且在 .NET 5 中重新出现,但它仍然有很多限制,所以我发现现在存在更好的选择:您可以使用包含在 Windows 10 中的应用程序交付机制,称为 AppInstaller,方法是打包您的应用程序在 MSIX 包或包中。
我在answer 中介绍了与该主题相关的发现
【讨论】: