20

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).

Tom Mayfield
  • 6,235
  • 2
  • 32
  • 43
  • 5
    @PeterMortensen How exactly a question that was asked in 2008 a duplicate of a question asked in 2011? Especially when it appears that this one contains better information – Kris Jul 05 '13 at 13:13

5 Answers5

17

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.

Phil Wright
  • 22,580
  • 14
  • 83
  • 137
  • You could look at both and decide which works best for you. ClickOnce just works out of the box but you have limited control over it. Using Updater application block takes more effort but you have more control because you can always alter the source code. – Phil Wright Sep 26 '08 at 13:01
  • ClickOnce only works for user (not machine-wide) installations. A much more powerful solution is Google Omaha: https://github.com/google/omaha. – Michael Herrmann Jun 23 '20 at 16:35
7

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)

synhershko
  • 4,472
  • 1
  • 30
  • 37
5

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.

Rob
  • 25,984
  • 32
  • 109
  • 155
  • why use a web service to check for updates? webclient is faster no? –  Sep 26 '08 at 14:22
4

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...

Kevin Fairchild
  • 10,891
  • 6
  • 33
  • 52
0

These days Windows can do such updates automatically for you with AppInstaller if your app is packaged in the MSIX package.

It downloads the new version of the app in another folder inside ProgramFiles\WindowsApps, then when a user runs the app via the start menu, the system knows what folder it should use. The previous version gets deleted when not in use.

If you want to know how to package your app this way I collected my findings in this answer.

Lev
  • 811
  • 12
  • 13