如何最好地实现 Windows 桌面和服务 C# 应用程序自动更新?
我的项目包含在用户的办公室台式电脑上运行的 WinForms、WPF 和 Windows 服务程序。我希望这些应用程序定期检查特定 URL 上是否有可用的新版本,自动下载新版本并用新版本替换自己,而不吸引任何用户注意(请记住,用户可能运行从 XP 到 7 的 Windows 并使用非特权帐户工作(可以是活动目录的一部分))。或者,整个更新包必须能够作为无人值守安装的 MSI 包进行分发。
关于实施这一点有什么建议吗?
My project contains WinForms, WPF, and Windows Service programs running on users' office desktop PCs. I want these applications to periodically check for new versions available at specific URL, automatically download new versions and replace themselves with new versions without attracting any user attention (keeping in mind that users may run Windows from XP to 7 and work using non-privileged account (which can be part of active directory)). Alternatively the whole update package has to be able to be distributed as an unattended-installed MSI package.
Any recommendations on implementing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你运气不好——遗憾的是所有的解决方案都很糟糕。您最好的选择(即我正在做的事情)是让一个应用程序定期检查它是否过期并向用户发出信号。现在,在我的例子中,“Wndows 服务”意味着“用户几乎一直登录到另一台计算机来控制该服务”,所以我有人需要真正发出警报。如果这不起作用,您将不得不重新实现诸如 Windows 更新服务之类的东西 - 遗憾的是没有预定义的方法可以做到这一点。
顺便说一句,没有用户关注根本不起作用。 - Windows 服务的安装/更新必须使用管理权限来完成,即使这些权限来自进行更新的 Windows 服务的权限。无论你做什么,都是肮脏的问题。
我会选择 MSI - 这样企业用户可以通过他们的软件管理(可以安装特权)推出该软件,无论他们在那里使用什么(有多个),而(家庭)最终用户只需使用管理员权限即可安装它,就像他们对其他软件所做的那样。也许每次开始检查中央服务器上的新版本时都会调用 Web 服务。
You are out of luck - sadly all solution suck. Your best bet (i.e. what I am doing) is have one application check whether it is out of date regularly and signal that to the user. Now, in my case "Wndows Service" means "with a user logged in on anothe computer pretty much all the time controlling the service", so I have someone to actually alert. If that does not work, you will have to reimplement something like the windows update service - there sadly is no predefined way to do that.
No user attention does not work at all, btw. - installation / update of windows services will have to be done with adminsitrative rights, even if those come from the priviledges of a windows service making the updates. Dirty issue whatever you do that.
I would go with an MSI - this way corporate users can roll that out via their software management (which can install priviledged), whatever they use there (there are multiple), and (home) end users just can install it with admin priviledges, like they do with every other software. Maybe do a web service call on every start checking for a new version on a central server.
这无疑是一个有问题的领域,没有简单的解决方案,特别是因为每个解决方案都有许多缺点,没有明显的赢家。
一种选择是仅替换 .dll 文件。这会阻止程序集的签名(因为您没有更新可执行文件本身),并且需要以某种方式构建应用程序,以便几乎所有应用程序逻辑都驻留在 dll 中。好处是您可以让 exe 本身检查更新并在可用时下载它们,但这只有在 dll 作为数据存储在其他地方(例如 appdata 中的应用程序插件文件夹)时才可行。
另一种选择是使用以本地管理权限运行的 Windows 服务来下载和安装更新。即使对于另一个 Windows 服务,这种情况也可以在没有用户干预的情况下发生。这里的技巧是不要让更新服务保持运行,而是从实际应用程序之一启动它(启动时或关闭时),然后在安装任何更新后让服务自行停止,以避免用户陷入困境具有另一个更新服务的系统。
最后,你应该认真考虑放弃“完全无人值守”的部分。用户可能会发现间歇性启动延迟是一个问题,并且传达您正在做的事情不会造成任何损害。我特别喜欢在启动时显示一个对话框,显示“找到新版本 - 安装(现在)(退出时)(稍后)”的解决方案,让我可以完全控制是否需要延迟。某些应用程序(如我所知道的每个扑克客户端)需要与服务器端软件同步,并且不会为您提供此选项,但仍显示“更新正在进行”对话框,以便我知道发生了什么。只要安装是自动的,我就不会担心提示。
This is certainly a problematic area with no easy solutions, especially because every solution has a number of drawbacks leaving no clear winner.
One option is to replace only .dll files. This prevents signing of the assemblies (since you're not updating the executable file itself) and requires the application to be structured in a way so that almost all of the application logic resides in dlls. The benefit is that you can have the exe itself check for updates and download them when available, but this is only feasible if the dlls are stored as data elsewhere (e.g. an application plugin folder in appdata).
Another option is to use a Windows service that runs with local administrative rights to download and install the updates. This can happen without user intervention, even for another Windows service afaik. The trick here is to not leave the update service running, but start it from one of the actual applications (either on startup or when it is closed) and then have the service stop itself after installing any updates, in order to avoid bogging down users systems with yet another update service.
Last, you should seriously consider dropping the "completely unattended" part. Users might find intermittent startup delays to be an issue and communicating what you are doing does not cause any harm. I particularly like the solution that displays a dialog on startup saying "new version found - install (now) (on exit) (later)", giving me complete control over whether I want the delay or not. Some applications (like every poker client I know of) need to be in sync with server-side software and do not give you this option, but still show the "update in progress" dialog so that I know what is going on. As long as the installation is automatic I wouldn't worry about the prompt.