使用 .NET/C# 应用程序自动更新的免费解决方案?

发布于 2024-10-09 04:28:42 字数 1261 浏览 10 评论 0原文

从搜索中我可以看到这个问题已经被问过一次又一次,但还不够充分,所以就在这里。我是一名没有预算的业余开发者。我一直在开发的一个程序需要定期修复错误,而我和用户已经厌倦了手动更新。

我,因为我目前的解决方案是通过 FTP 和网站上的下载链接更新文本文件,然后希望用户看到“有更新消息”,最后让他们不厌其烦地手动下载更新,好吧坦白说,很糟糕。

用户,因为,“你打算实施自动更新吗?” “会有自动更新功能吗?”如果我碰巧搞砸了更新过程,干草叉就会开始出现。

过去我研究过:

  • WinSparkle - 没有应用内更新,DLL 为 500 KB。我当前的解决方案是可执行文件中的几KB,并且没有应用内更新。
  • .NET 应用程序更新组件 - 不幸的是我无法理解文档。
  • Eduardo Olivera 的 AutoUpdate - 除了处理文件之外,这似乎不支持任何其他操作未使用的。
  • wyUpdate - wyBuild 不是免费的,虽然 wyUpdate 规范可用,但它太复杂且耗时经过。
  • AppLife 更新 - 同上最后一句。
  • ClickOnce - 实现启动时启动的解决方法是巨大的、可怕的,对于如此简单的功能来说不值得。出版是一件痛苦的事;对于没有 FrontPage Extensions 的服务器,需要手动 FTP 并替换所有文件

令人非常失望的是,当您为 Mac OS X 提供了非常漂亮且简单的实现(例如 Sparkle< 时,Windows 上的情况却是这样) /a>.

From searching I can see this has been asked time and time again, but not adequately enough, so here goes. I'm a hobbyist developer with no budget. A program I've been developing has been in need of regular bugfixes, and me and users are getting tired of having to manually update.

Me, because my current solution of updating a text file through FTP and my download links on the website, and then hoping users will see the "there's an update message", and finally getting them to then be bothered to manually download the update, well quite frankly, is abysmal.

Users, because, well, "Are you ever going to implement auto-update?" "Will there ever be an auto-update feature?" And if I happen to screw up the update process, pitchforks start arriving.

Over the past I have looked into:

  • WinSparkle - No in-app updates, and the DLL is 500 KB. My current solution is a few KBs in the executable and has no in-app updates.
  • .NET Application Update Component - Unfortunately I can't comprehend the documentation.
  • Eduardo Olivera's AutoUpdate - This doesn't appear to support anything other than working with files that aren't in use.
  • wyUpdate - wyBuild isn't free, and while the wyUpdate specification is available, it's simply too complex and time-consuming to go through.
  • AppLife Update - Ditto the last sentence.
  • ClickOnce - Workarounds for implementing launching on startup are massive, horrendous and not worth it for such a simple feature. Publishing is a pain; manual FTP and replace of all files is required for servers without FrontPage Extensions.

It's quite disappointing that the situation on Windows is like this when you've got really nice and simple implementations for Mac OS X like Sparkle.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

唱一曲作罢 2024-10-16 04:28:42

自己实现吧!这会很有趣。创建一个仅包含更新逻辑的单独应用程序,即在线获取文件、下载它们、替换本地文件,并将其直观地显示给用户。

因此,您的主应用程序可以检查更新,如果存在,它将提示用户更新的可能性。如果用户愿意,它将运行更新程序,关闭自身(以便可以进行更新)并立即完成。

您唯一需要的东西都可以在 C#、FTP 访问和 IO 中轻松获得。

编辑:我知道这不是一件非常容易的事情,但这是学习的绝佳机会:

  • 如何(正确)以可以扩展到 ftp、http 等的抽象方式下载文件
  • 。 (正确地)对许多文件执行一个简单的任务 - 复制或覆盖它们(这意味着错误处理)。
  • 练习(因为没有“正确”的方法)对软件进行分层和封装。
  • 如何处理操作系统/其他软件(防病毒/防火墙/等)不配合的情况。

这些都是我们都需要充分了解的事情 - 如果需要几周的时间来编写更新程序,则意味着您需要几周的学习时间。如果您不需要学习,那么是时候磨练您的技能了!如果您不知道是否需要,那么是时候找出答案了! :)

注意:我知道我确实需要学习更好的文件和网络 I/O

Implement it yourself! It will be fun. Create a separate application that only contains update logic i.e., fetch the files online, download them, replace local files, and show that visually to the user.

So your main application could check for updates, and if they exist it would prompt the user with the possibility to update. If the user wants to, it will run the update program, close itself (so the update can happen) and presto.

The only things you need are readily avaliable in C#, FTP access and IO.

Edit: I know it's not something terribly easy, but it's a perfect chance to learn:

  • How to (properly) download files, in an abstracted way that can be extended to ftp, http, etc.
  • How to (properly) do a simple task over many files - copying or overwriting them (this implies error handling).
  • Practice (because there's no "proper" way) to layer and encapsulate a piece of software.
  • How to deal with the OS/other software (antivirus/firewall/etc) not cooperating.

These are all things we all need to know well - If it takes some weeks to code an updater it means you were needing some weeks of learning. If you don't need to learn, time to hone your skills! If you don't know if you need, time to find out! :)

Note: I know I do need to learn better file and network I/O

梦回旧景 2024-10-16 04:28:42

早就应该更新了,哎呀!

但无论如何,我已经使用 SparkleDotNET 一段时间了,它的工作效果非常好。到处都有一些小错误,但我已经帮助消除了其中一些错误,希望我也能够消除其他错误:)

对于那些有时间运行 Visual Studio 发布功能的人,并且其应用程序相对独立,并且不需要启动时启动之类的任何内容,我肯定会推荐 ClickOnce。 MetroTwit 使用它,并且它有一个很好的应用内更新程序界面,因此它看起来很灵活(至少在某些方面)程度)。对于在启动时启动,可能可以这样做,但是这样做的方法非常hacky并且效果不佳。

Should've updated this ages ago, oops!

But anyway, I've been using SparkleDotNET for a while now and it's been working absolutely wonderfully. There's a few little bugs here and there but I've already helped get some of them squashed, and hopefully I'll be able to get rid of the others too :)

For those who have the time to run the publish functionality of Visual Studio, and whose app is relatively self-contained, and doesn't require anything like launching on startup, I'd recommend ClickOnce for sure. MetroTwit uses it and it's got a nice in-app updater interface, so it seems flexible (at least to a certain degree). For launching on startup, it's possible to do so, but methods to do so are quite hacky and don't work that well.

烟花肆意 2024-10-16 04:28:42

您可以尝试来自 GitHub 的 Autoupdater.NET 我自己开发了它,它在我的应用程序中运行得很好应用程序。您只需在代码中添加一行即可完成。此外,它是开源的,因此您可以根据需要进行修改和使用。

You can try Autoupdater.NET from GitHub I developed it my self and it works very well in my applications. You just have to add one line in your code and it's done. Also, it is open source so you can modify and use as you want.

九八野马 2024-10-16 04:28:42

您甚至可以不开发外部应用程序,而是将其实现为应用程序的模块,例如命名空间更新,并使用动态程序集生成器生成exe,启动它并退出app main,然后在以下情况下再次启动它:更新将完成。

更多信息

You even can not to develop an external application but implement it as your application's module, e.g. into namespace Update, and use dynamic assembly builder to generate an exe, start it and exit app main, start it again when update will be finished.

Some more info.

小傻瓜 2024-10-16 04:28:42

还有 DDay update,它是开源的,由我的一位同事使用顾客。我们/他们主要对它在 Windows 服务的上下文中感兴趣,因为它在这方面工作得相当好。

There is also DDay update which is open source and is used by one of my customers. We/they are primarily interested in it in the context of a windows service at it works reasonably well for that.

ま昔日黯然 2024-10-16 04:28:42

如需更强大的解决方案,您可能需要查看 Google Omaha。 Chrome 就是这么用的。当应用程序未运行时,您可以在后台获取应用内更新和自动更新。

For a more powerful solution, you may want to look at Google Omaha. It's what Chrome uses. You can get both in-app and automatic updates in the background when your application isn't running.

江心雾 2024-10-16 04:28:42

尝试使用 MD5-Update,它完全免费且简单,无需在您的应用程序中进行配置,只需添加库并发布文件。
https://github.com/jrz-soft-mx/MD5-Update/< /a>

“MD5-更新”

1.您需要一个带有 PHP 的 Web 服务器来发布您的文件,请包含 updt.exe。

WebServer

2.添加index.php作为更新文件的列表。可在 github 存储库 https://github 上获取。 com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o 使用此代码创建新应用程序。

<?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.在您的项目4中添加nuget存储库

PM> Install-Package MD5.Update

。当您的应用程序明星时,使用更新文件夹 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 文件夹到 app.updt.exe。可在 github 存储库 https://github 上获取。 com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o 使用此代码创建新应用程序。

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();
}

Try with MD5-Update it is absolutely free and easy no configuration need in your app only add library and publish the files.
https://github.com/jrz-soft-mx/MD5-Update/

MD5-Update

1. Your need a web server with PHP for publish your files please include updt.exe.

WebServer

2. Add index.php for make list of update files. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.

<?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);
?>

enter image description here

3. Add nuget repository at your proyect

PM> Install-Package MD5.Update

4. Call the library when your app stars, with your update folder url, update all files and download your new app on updt folder, for replace your app need 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();
}

enter image description here

enter image description here

5. updt.exe for replace the current app with the new app updt folder to app. aviable on github repository https://github.com/jrz-soft-mx/MD5-Update/blob/main/Tools/Tools.zip o create new app with this code.

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();
}
错爱 2024-10-16 04:28:42

所有的人都是对的,特别是看看 abatishchev 的回复。但我认为其他一些东西需要那个人忘记了。尝试“模块化”开发您的项目。尽可能将它们放入类库中。因此在修复操作期间替换其中一个。考虑一下数据库修复。有时您需要向数据库表添加一列。什么你会为这些情况做些什么吗?

我开发了一个更新项目。其中,我有三种修复。
1-程序运行有BUG,需要替换DDL文件
2-程序中存在错误,需要更新当前程序执行文件
3-错误或更改数据库并需要

在网络主机上的表中执行sql服务器查询我放置版本历史记录,每次我的应用程序开始检查新版本。如果存在任何更新,检查其类型并下载它根据更新类型和参数执行适当的操作祝

你好运伙计

all guys are right specially look at the abatishchev reply.but i think some thing other need that guy forgot it. try to develop your project "modular".put them your code in class library as you can.so during the fix operation replace one of them.think a bout database fix.some time you need to add a column to your database table.what do you do for these cases?

a have developed an update project.in that , i have three kind of fixes.
1- BUG in program operation and need to replace a DDL file
2- Bug in program and need to update currently program executive file
3- bug or change the database and need to execute a sql server query

in a table on web host i put the version history and every time that my app start check for new version.if any update exist check for its type and download it and do the suitable action depend on the update kind and parameters

good luck dude

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文