问题描述
在写我自己的自动更新程序,有没有,我应该遵循的一般框架?
When writing my own auto updater, is there a general framework that I should be following?
前一段时间,我读了应如何创建'启动strapper,将在主应用程序之前,先装入(因为运行appilation不能因文件锁定等进行更新。)
A while ago I was reading up on how one should create a 'boot strapper' that will load first before the main application (since a running appilation can't be updated due to file locks etc.)
所以任何提示/这个最佳做法?
So any tips/best practices for this?
推荐答案
你可能必须写你自己的。至于提到的,其基本思想是把你的程序的最新版本(我假设一个EXE)的服务器上,然后让应用程序检查与服务器启动时,并下载EXE从服务器,如果是较新的版本。
You'll probably have to write your own. As FOR mentioned, the basic idea is to put the latest version of your program (I'm assuming an EXE) on the server, and then have your application check with the server when it starts, and download the EXE from the server if it's a newer version.
我通常会实现这是该应用程序在启动时调用Web服务。关于这种方法的情侣警告:
I've usually implemented this as a web service that the application calls at startup. A couple of warnings about this approach:
-
Web服务方法需要获得服务器上的EXE文件的版本号,并将其与调用者的版本号。如果您使用Assembly类来读取服务器EXE文件的版本号,这将作为Web服务的实例运行(至少20分钟)锁定文件,只要。这样一来,你有时可能会遇到麻烦更换EXE服务器与较新的版本上。使用的AssemblyName类代替 - 这可以让你阅读组装方式无需加载组件(和锁定它)
The web service method needs to get the version number of the EXE on the server and compare it to the version number of the caller. If you use the Assembly class to read the version number of the server EXE, this will lock the file for as long as the web service instance is running (at least 20 minutes). As a result, you may sometimes have trouble replacing the EXE on the server with a newer version. Use the AssemblyName class instead - this allows you to read the assembly info without loading the assembly (and locking it).
调用者应用程序不能用新版本替换它自己的文件 - 你不能删除或更新正在运行的应用程序文件。它的可以的事,但是,是运行时重命名自己的文件。因此,在自动更新,关键是应用程序可以重命名本身(如MyApplication.exe到MyApplication_OLD.exe),下载新版本的到应用程序文件夹(名为MyApplication.exe),通知用户更新已发生,需要应用程序的重新启动,然后结束。当用户重新启动该应用程序,这将是用于启动新版本 - 这个版本检查并删除旧版本
The caller application can't replace its own file with the new version - you can't delete or update a running application file. What it can do, however, is to rename its own file while running. So the trick on an auto-update is for the application to rename itself (e.g. "MyApplication.exe" to "MyApplication_OLD.exe"), download the new version into the application folder (named "MyApplication.exe"), notify the user that an update has occured which requires a restart of the application, and then end. When the user restarts the application, it will be the newer version that starts - this version checks for and deletes the old version.
做一个自动更新自动重新启动应用程序后,这样的更新是非常棘手的(它涉及到踢了另一个进程,然后结束自己的进程之前自动重启过程踢)。我从来没有一个用户抱怨不必重新启动应用程序。
Doing an auto-update that automatically restarts the application after an update like this is very tricky (it involves kicking off another process and then ending its own process before the auto-restart process kicks in). I've never had a user complain about having to restart the app.
这篇关于写我自己自动更新程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!