如何在.NET程序自动更新?自动更新、程序、如何在、NET

2023-09-03 10:50:00 作者:戎马

我已经写了一个程序,更新自己,如果发现服务器上的一个较新的版本,但我发现很难实现干净。

I've written a program that updates itself if it finds a newer version on a server but I'm finding it hard to implement cleanly.

检查远程服务器和下载文​​件中很容易,但是然后呢?它不能简单地File.Copy(newversion.exe,myprogram.exe),因为myprogram正在运行,且该文件被锁定。

Checking a remote server and downloading the file are easy enough but then what? It can't simply File.Copy("newversion.exe","myprogram.exe") because myprogram is running and the file is locked.

我通过下载两个文件动态网页和更新做。 myprogram然后启动更新并退出。 更新等待两秒钟,做副本,然后启动myprogram(也就是现在的更新版本),然后退出。 myprogram查找更新,当它启动其删除,并动态网页,如果发现他们。 mypogram现在的新版本没有任何文件留奠定左右。

I do it by downloading two files newversion and update. myprogram then launches update and exits. update waits for two seconds, does the copy, then launches myprogram (which is now the updated version) and exits. myprogram looks for update when it starts and deletes it and newversion if it finds them. mypogram is now the new version with no files left laying around.

必须有比这更好的办法有啥.NET的方式为一个程序来更新自己?

There must be a better way than this so what's the .net way for a program to update itself?

PS。很抱歉,如果这个问题出现了两次 - 我有一个堆栈溢出坏页面,我第一次提出它

PS. Sorry if this question appears twice - I got a 'stack overflow is broken' page the first time I submitted it.

推荐答案

看看的 ClickOnce部署给你所需要的。