Jørn Schou-Rode
Jørn Schou-Rode

Reputation: 38346

What is the easiest way to update a .NET Windows service in production?

Say, you have a custom Windows service installed on a server. The service is written using .NET, and it is installed using either InstallUtil, an MSI package or the ManagedInstallerClass (if it makes a difference, pick the one that solves the problem). Regularly, you will need to deploy changes to the service, and of course you want to make this as easy as possible.

Is it "safe" to just stop the service, replace the .exe file and restart the service? Or would you have to uninstall and reinstall with the new .exe file? Would it be easier if the "evolving" part of the service was split into a separate assembly? Are there any tools or APIs that might be of help in either development or deployment of the service?

Upvotes: 8

Views: 5394

Answers (3)

Dirk Vollmar
Dirk Vollmar

Reputation: 176219

For updating services we either use MSI packages (in case we provide an installer to our customers anyway) or a short script that handles stopping and uninstalling the old version of service, and then copies, installs and starts the new version.

For scripting the deployment of local services you can use standard Windows commands such as net start and net stop in combination with installutil, for remote deployment you could e.g. use psexecute and psservice from SysInternals.

Upvotes: 2

3Dave
3Dave

Reputation: 29051

Just stop the service, replace the EXE and restart it. This should probably be part of your installer. Separating it into separate assemblies just for the sake of reinstall is a rabbit hole.

Upvotes: 5

Noon Silk
Noon Silk

Reputation: 55112

I just stop the service and replace the exe; it's safe to do that.

You can have it so that your service begins to load modules, and you develop your system that way; it would work, but it may be overly complicated, or not, depending on what exactly you're wanting to do.

Upvotes: 12

Related Questions