Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Self-update / shadow-copy with Asp.Net Core

I'm writing a Asp.Net Core application which should be able to update itself (replace its own binaries while running).

This MSDN article describes shadow copying with the classical .Net framework, which would be exactly what I need. But the whole AppDomain thing is missing in .Net Core.

So my questions are:

  • Is there an alternative way in .Net Core to enable shadow copying the assemblies?
  • Are there other mechanisms in .Net Core that allow to build a self-updating application?
like image 742
Robert Hegner Avatar asked Mar 14 '17 08:03

Robert Hegner


Video Answer


2 Answers

Since there is no built in mechanism in .NET Core for doing this, I ended up implementing my own custom solution. It works roughly like this:

  1. The running application downloads and extracts new binaries to a new folder.
  2. The running application starts a small updater process. The following parameters are passed to the updater process via command line:
    • Process id of the running application
    • Binary path of the running application
    • Path of the downloaded binaries
  3. The running application exits itself.
  4. The updater process waits until the running application has exited (using the process id) or forcefully kills the running application if it doesn't exit by itself within a given timeout.
  5. The updater process deletes the existing binaries and copies the new downloaded binaries over.
  6. The updater process starts the new version of the main application.

Make sure you do as much as possible in the main application (downloading, unpacking, validation, ...) and keep the updater process as simple as possible (minimize risk of failing).

This approach has proven to be quite stable.

like image 69
Robert Hegner Avatar answered Sep 24 '22 23:09

Robert Hegner


There's no build in shadow copying facilities in .NET Core

like image 30
davidfowl Avatar answered Sep 24 '22 23:09

davidfowl