我不“明白”程序如何自我更新。我怎样才能更新我的软件?
假设我创建了一个 .exe 文件,一切都很顺利。太棒了,它有效。
假设我在软件上开发了一项新功能,并且我希望它可供已经拥有旧版本的人使用,我怎样才能让软件找到我的新版本,修补它,然后继续它的业务。
我似乎无法思考这个问题。
谢谢。
编辑: 对于造成的混乱,我深表歉意,但我的意思是一个更代码明智的答案。我的代码中有什么特殊的东西我应该允许更新吗?
例如,如果我想添加一个新功能,我如何向已经打包的 .exe 添加“方法”? :S 那让我旋转起来。
Say I make an .exe file and everything is peachy. Wonderful it works.
Say I worked on a new feature on the software and I want it to be available for people who already have the older version, how can I make the software find my new version, patch it, and then go about it's business.
I can't seem to wrap my head around the issue.
Thank you.
EDIT:
I'm sorry for the confusion, but I was meaning a more code-wise answer. Is there something special in my code I should have to allow updating?
For example, if I want to add a new feature, how can I add a "method" to an already packaged .exe? :S That has me in a swivel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
通常过程如下:
当然您可以有很多变体,但这是基本的方法来做到这一点。
至少在 Windows 上,某些软件会安装一个始终打开的更新程序守护程序,并检查它所处理的软件的新更新(例如 GoogleUpdater)。
Usually the process is as follows:
Of course you can have many variations, but this is the basic way to do it.
On Windows, at least, some software install an updater daemon that is always on and checks for new updates of the software it takes care (GoogleUpdater, for example).
一个流行的解决方案是实际上用一个单独的进程来替换必要的文件。
您是否注意到 Firefox 每当更新时都必须重新启动?嗯,这是因为一个单独的进程 (updater.exe) 正在下载文件,关闭 Firefox,替换文件,然后再次启动 Firefox。
编辑 当然,这假设您正在托管更新程序可以检查的在线更新列表(RSS 提要,甚至是简单的文本文件)。
A popular solution is to actually have a separate process replace the necessary files.
Have you ever noticed that Firefox has to restart whenever it updates? Well, that is because a separate process (updater.exe) is downloading the files, closing firefox, replacing the files, and then starting firefox again.
edit of course this assumes you're hosting a list of updates online that the updater program can check (an RSS feed, or even a simple text file).
您需要查看 单击一旦部署。
这将创建一个可下载的安装 exe,您可以将其加载到网络上。用户要么就地运行它,要么下载并运行它。这会将您的 exe 包装在代码中,该代码将检查 Web 位置(以您选择的频率)是否有更新。如果找到,它将为用户安装。
您无需对代码进行任何特殊更改即可启用此功能。除了增加版本号之外。只需照常修改和扩展您的代码、编译、构建、打包和上传即可。
需要注意的一件事是 ClickOnce 不支持安装需要管理访问权限的应用程序:
因此,如果您的应用程序需要管理员级别的访问权限才能运行甚至安装,那么它不适合您。
You need to look at Click Once Deployment.
This creates a downloadable setup exe which you load up to the web. The user either runs this in place or downloads and runs it. This wraps your exe in the code that will check the web location (at a frequency of your choosing) for updates. If it finds one it will install it for the user.
You don't have to make any special changes to your code to enable this. beyond incrementing the version number. Just modify and extend your code as normal, compile, build, package and upload.
One thing to note is though that ClickOnce doesn't support installing applications that require administrative access:
So if your application requires admin level access to run or even install then it's not the solution for you.
一个想法 - 您可以有一个加载应用程序来为您进行检查,然后如果有必要在启动之前更新主应用程序的 exe?
One idea - you could have a loader application that does the check for you, then if necessary updates the main app's exe before launching it?
对于 Windows(通常是由于 Windows 在执行时锁定 .exe 文件)
For windows (generally due to windows locking the .exe file while it's being executed)
好吧,通常的方法是您的应用程序定期检查某个地方(通常在 Internet 上)是否有新版本。这可能是在每次启动时或每周一次或其他什么。
例如,您可以简单地在其中放置包含当前版本号的文本文件。如果该版本比已安装应用程序的版本更新,您可以下载更新程序(不要忘记签名并检查签名)并安装新版本。
Well, the usual way is that your application checks somewhere (usually on the Internet) regularly for new versions. This may be on every startup or once a week or whatever.
There you can simply put for example a text file containing the current version number. If that one would be newer than the version of the installed application you can download an updater (don't forget to sign and check signatures) and install the new version.
让您的应用程序偶尔通过网络向您的网络服务器发出请求。让该请求返回一个包含版本号和最新版本安装程序链接的文件。如果该版本号大于当前运行的程序认为的版本号,请让您的程序下载新的安装文件并启动它。
Make your app occasionally make a request over the web to your webserver. Have that request return a file that contains the version number and a link to the newest version of your installer. If that version number is greater than the version number the currently-running program thinks it is, have your program download the new setup file and launch it.
您不修改当前的 .exe。
您启动一个单独的进程来下载文件的新版本。新版本取代旧版本。无需修改。
You don't modify your current .exe.
You launch a separate process that downloads a new version of the file. The new version replaces the old version. No modification needed.
从代码的角度来看,我喜欢采用一种方法,该方法由一个名为 IRun 的简单接口和另一个名为 IUpdated 的简单接口组成:
现在我的主应用程序将使用反射加载并“运行”一个库,从而启动真正的应用程序。
主应用程序可执行文件将执行以下步骤:
update 方法对实际应用程序的更新执行相同的步骤。
最后
当然,如果您想“自己动手”,ClickOnce 实际上也是一个非常好的方法,可能更好,但控制权较少。主应用程序可执行文件足够简单,可以避免自行更新或无论如何都应该更新。
From a code point of view I like to have an approach that consists on a simple interface called IRun and another one called IUpdated:
Now my main application will just load and "run" a library using reflection which in turns launch the real application.
The main application executable will do this steps:
The update method does the same steps for updates to the actual application.
Finally
That's of course provided you want to "do it yourself", ClickOnce is actually a very good method too, probably better but gives you less control. The main application executable is simple enough to avoid having to update it itself or should be anyway.