Auto update for WinForms application

2019-01-21 11:51发布

When creating an auto updating feature for a .NET WinForms application, how does it update the DLLs and not affect the currently running application?

Since the application is running during the update process, won't there be a lock on the DLLs (because those DLLs will have to be overwritten during the update).

4条回答
疯言疯语
2楼-- · 2019-01-21 12:01

You'll have to shutdown your application and restart it, as other people have already commented.

I wrote an open-source code to do just that in a transparent mode - including an external update application to do the actual cold update. See http://www.code972.com/blog/2010/08/nappupdate-application-auto-update-framework-for-dotnet/

The code is at http://github.com/synhershko/NAppUpdate (Licensed under the Apache 2.0 license)

查看更多
Evening l夕情丶
3楼-- · 2019-01-21 12:04

I have a seperate 'launcher' application that checks for updates via a web service. If there are updates, it downloads them and then executes my application, which is in a seperate assembly.

The other alternatives are using things like ClickOnce, or downloading the files to a seperate area and restarting the app, as someone else mentioned.

Be warned about ClickOnce, though - it's not as flexible as it sounds. And if you deploy to a system that requires elevating your program to a higer security level to run, you might run into problems if you don't have a certificate for your app installed. I found it very difficult to get straight answers on the Internet to things like certificate management when it comes to ClickOnce. If you have a complex app, you may want to just roll your own updater, which is what I ended up having to do.

查看更多
贪生不怕死
4楼-- · 2019-01-21 12:10

If you publish via ClickOnce, all of that tends to be handled for you. It has it's own pro's and con's but usually easier than trying to code it all yourself.

Both Wikipedia and 15seconds have decent info on using ClickOnce, how it works, etc.

As others have stated, ClickOnce isn't as flexible as rolling your own solution but it is a LOT less complicated. It has a small learning curve at first, but with pretty much everything bundled into Visual Studio and the use of Wizards, it usually doesn't take long to stumble onto a working solution.

As deployments get more complex (i.e. beyond than just having prerequisites or application code that needs updating) and you need to do a lot of post-install or pre-install tasks, there are things like WiX which give you somewhat of a hybrid solution between Windows Installer and ClickOnce, with the cost of flexibility being a much steeper learning curve.

The only reason I try to avoid custom installers is that you end up spending way too much time trying to get it just right to handle a bunch of different "What If" scenarios...

查看更多
Emotional °昔
5楼-- · 2019-01-21 12:20

Usually you would download the new files into a separate area. Then shutdown and restart and at startup you look for and use the new files if found. Always keeping a last known working version on the side so that the user can revert to something that definitely works if the download causes problems.

ClickOnce is a good technology from Microsoft that does this for you and you can use it directly from Visual Studio 2008.

查看更多
登录 后发表回答