自动更新 .NET 应用程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/819647/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto update .NET applications
提问by Aleksandar Vucetic
We are in a process of developing a really complex system consisting of several WCF services, ASP.NET MVC applications, administration tools (Windows Forms apps)... Some of those, will have instances running on several servers. We are looking for a good auto update solution for such a system. Most likely, we would need a separate auto update application (service) that will do the job, or some centralized admin application that will know about versions of all installed instances and do the update remotely. Is there any good product/library, made for this purpose, that you know about or had experience with?
我们正在开发一个由多个 WCF 服务、ASP.NET MVC 应用程序、管理工具(Windows 窗体应用程序)组成的非常复杂的系统......其中一些将在多个服务器上运行实例。我们正在为这样的系统寻找一个好的自动更新解决方案。最有可能的是,我们需要一个单独的自动更新应用程序(服务)来完成这项工作,或者一些集中的管理应用程序来了解所有已安装实例的版本并远程执行更新。有没有为此目的而制作的好的产品/库,您知道或有过使用经验?
回答by dr. evil
Personally I'm using a very simple methodology for any kind of auto-update:
我个人对任何类型的自动更新都使用一种非常简单的方法:
- Have an installer
- Check the new version (simple WebClient and compare numbers with your current AssemblyVersion)
- If the version is higher download the latest installer (should be over SSL for security reasons)
- Run the downloaded installer and close the application. (in this stage you need to have admin privileges if your installer requires you to be an admin)
- 有安装人员
- 检查新版本(简单的 WebClient 并将数字与您当前的 AssemblyVersion 进行比较)
- 如果版本更高,请下载最新的安装程序(出于安全原因应该通过 SSL)
- 运行下载的安装程序并关闭应用程序。(在此阶段,如果您的安装程序要求您是管理员,则您需要拥有管理员权限)
The installer should take care of the rest. This way you'll always have the latest version and an installer with a latest version.
安装人员应该负责其余的工作。这样,您将始终拥有最新版本和最新版本的安装程序。
回答by Wyatt O'Day
Let me start by saying I'm the founder of the company that has a complete updating solution which includes:
首先让我说我是公司的创始人,该公司拥有完整的更新解决方案,其中包括:
- An open source updater, wyUpdate, written in C# [BSD license]
- The open source AutomaticUpdater controlthat you can just add to your .NET app's form [LGPL license]
- wyBuild is used to build patchesand manage your versions
- 一个开放源码更新器,wyUpdate,C#编写的[BSD许可证]
- 该开源AutomaticUpdater控制,你可以只添加到您的.net应用程序的形式[LGPL许可证]
- wyBuild 用于构建补丁和管理您的版本
wyUpdate handles all of the Vista/Windows 7 UAC problems and all the file permission problems that inevitably pop up when you're trying to update complex software.
wyUpdate 可以处理所有 Vista/Windows 7 UAC 问题以及在您尝试更新复杂软件时不可避免地出现的所有文件权限问题。
We also offer free licenses to wyBuild for open source projects, but if you're just looking to build your own updater you can cannibalize our source code freely.
我们还为开源项目提供wyBuild 的免费许可证,但如果您只是想构建自己的更新程序,您可以自由地蚕食我们的源代码。
That being said, if you want to build your own updater here are some tips:
话虽如此,如果您想构建自己的更新程序,这里有一些提示:
Building your own updater
构建自己的更新程序
A good place to start is the wyUpdateand AutomaticUpdatersource code I mentioned above. You can cannibalize it and use it for your own purposes. Some of the algorithms it contains:
一个很好的起点是我上面提到的wyUpdate和AutomaticUpdater源代码。您可以蚕食它并将其用于自己的目的。它包含的一些算法:
- Full Windows Vista / Windows 7 UAC support
- Ability for limited users to check and then update if they have credentials
- Support for wonky corporate inernet. (If you've ever worked with a corporation this is a real problem).
- Quick extracting, patching, and installing of files.
- Registry support.
- Roll back files & registry on error or cancellation by the user
- Self-update (no files left behind)
- 完整的 Windows Vista / Windows 7 UAC 支持
- 能够让受限用户检查并更新他们是否拥有凭据
- 支持不稳定的企业互联网。(如果你曾经与一家公司合作过,这是一个真正的问题)。
- 快速提取、修补和安装文件。
- 注册表支持。
- 在用户出错或取消时回滚文件和注册表
- 自我更新(不留下任何文件)
We also have the file specifications here.
Automatic updating
自动更新
Since being automatic is a requirement let me tell you how we do it with our AutomaticUpdater control.
由于自动是一项要求,让我告诉您我们如何使用AutomaticUpdater 控件做到这一点。
We use named pipes to communicate between the standalone updater (wyUpdate) and the Automatic Updater control sitting on your program's form. wyUpdate reports progress to the Automatic Updater, and the Automatic Updater can tell wyUpdate to cancel progress, to start downloading, start extracting, etc.
我们使用命名管道在独立更新程序 (wyUpdate) 和位于程序窗体上的自动更新程序控件之间进行通信。wyUpdate 向自动更新器报告进度,自动更新器可以告诉 wyUpdate 取消进度、开始下载、开始解压等。
This keeps the updater separate from your application.
这使更新程序与您的应用程序分开。
In fact, the exact named pipes C# code we use is included in an article I wrote a little while back: Multi-process C# app like Google Chrome.
事实上,我们使用的确切命名管道 C# 代码包含在我不久前写的一篇文章中:Multi-process C# app like Google Chrome。
回答by synhershko
Here's an open-source solution I wrote to address specific needs we had for WinForms and WPF apps. The general idea is to have the greatest flexibility, at the lowest overhead possible.
这是我编写的一个开源解决方案,用于解决我们对 WinForms 和 WPF 应用程序的特定需求。总体思路是以尽可能低的开销获得最大的灵活性。
So, integrationis super-easy, and the library does pretty much everything for you, including synchronizing operations. It is also highly flexible, and lets you determine what tasks to execute and on what conditions - you make the rules (or use some that are there already). Last by not least is the support for any updates source(web, BitTorrent, etc) and any feed format- whatever is not implemented you can just write for yourself.
因此,集成非常简单,该库几乎可以为您完成所有工作,包括同步操作。它也非常灵活,可以让您确定要执行的任务以及在什么条件下执行 - 您可以制定规则(或使用一些已经存在的规则)。最后同样重要的是对任何更新源(网络、BitTorrent 等)和任何提要格式的支持- 无论没有实现,您都可以自己编写。
Cold updates (requiring an application restart) is also supported, and done automatically unless "hot-swap" is specified for the task.
冷更新(需要重新启动应用程序)也受支持,除非为任务指定了“热交换”,否则会自动完成。
This boild down to one DLL, less than 70kb in size.
这归结为一个 DLL,大小不到 70kb。
More details at http://www.code972.com/blog/2010/08/nappupdate-application-auto-update-framework-for-dotnet/
更多详情请访问http://www.code972.com/blog/2010/08/nappupdate-application-auto-update-framework-for-dotnet/
Code is at http://github.com/synhershko/NAppUpdate(Licensed under the Apache 2.0 license)
代码位于http://github.com/synhershko/NAppUpdate(在 Apache 2.0 许可下获得许可)
I plan on extending it more when I'll get some more time, but honestly you should be able to quickly enhance it yourself for whatever it currently doesn't support.
当我有更多时间时,我计划进一步扩展它,但老实说,您应该能够自己快速增强它当前不支持的任何内容。
Auto-updating WCF services and ASP.NET websites should be possible to do as well with it, using "hot-swap" of files and "iisreset" task where necessary.
自动更新 WCF 服务和 ASP.NET 网站应该也可以使用它,在必要时使用文件的“热交换”和“iisreset”任务。
回答by Peter Lillevold
ClickOnce for your admin tools.
ClickOnce 为您的管理工具。
回答by Kobus Smit
We investigated a handful of options and decided to use the AppLife Updatelibrary for our enterpise project.
我们调查了一些选项,并决定为我们的企业项目使用AppLife 更新库。
AppLife Update can quickly and easily add auto update functionality for your .NET apps but is also flexible because of it's comprehensive API.
AppLife Update 可以快速轻松地为您的 .NET 应用程序添加自动更新功能,但由于其全面的 API 也非常灵活。
See the full list of features and some demo videos on their website.
在他们的网站上查看完整的功能列表和一些演示视频。
回答by Cheeso
For simple WPF applications, those that maybe use Xcopy install, you can use this AppUpdater module. It's one source module, just a few lines of code, to add update capability to a simple WPF app.
对于简单的 WPF 应用程序,那些可能使用 Xcopy 安装的应用程序,您可以使用这个 AppUpdater 模块。它是一个源模块,只需几行代码,即可为简单的 WPF 应用程序添加更新功能。
It's free.
免费。

