Larry Smithmier
Larry Smithmier

Reputation: 2731

I want my C# Windows Service to automatically update itself

Is there a framework that can be used to enable a C# Windows Service to automatically check for a newer version and upgrade itself? I can certainly write code to accomplish this, but I am looking for a framework that has already been implemented and (most importantly) tested.

[edit] Here is a link to a similar question with links to modern projects that help accomplish this: Auto-update library for .NET?

Upvotes: 37

Views: 35042

Answers (9)

datchung
datchung

Reputation: 4622

I was looking into NetSparkle as others have suggested and came across these alternatives. AutoUpdater.NET is my pick due to ease of use and feature set.

Upvotes: 1

jebbie
jebbie

Reputation: 1457

You can use NetSparke, it supports .NET Core 3+ (.NET 5+) and .NET Framework 4.5.2+. It comes with built-in UI or without any UI at all. You can handle all the events by yourself. It works with an appcast.xml (and also have a utility to generate that), is platform independent and just works out of the box.

Just work trough the documentation on their repository and check the example app ;-)

Upvotes: 1

Michael Herrmann
Michael Herrmann

Reputation: 5003

I've had good experiences with Google Omaha for updating Windows Services. It can generally be used to update any Windows application but there is a tutorial for using it to update a Windows Service.

In comparison to other update frameworks, Omaha is more complex, but also the most powerful. This is because Google (and now also Microsoft) use it to update their browsers on billions of PCs. However, once it's set up and you understand the basics, it is a very nice experience.

Upvotes: 4

stephbu
stephbu

Reputation: 5082

The only way to unload types is to destroy the appdomain. To do this would require separation of your hosting layer from your executing service code - this is pretty complex. (sort of like doing keyhole surgery)

May be easier to either a) run a batch task or b) in-service detect updates then launch a seperate process that stops the service, updates assemblies etc. then restarts it.

If you're interested in the former, the MSDN patterns and practices folk wrote an app updater block that you adapt to your service.

https://web.archive.org/web/20080506103749/http://msdn.microsoft.com/en-us/library/ms978574.aspx

Upvotes: 20

Omaer
Omaer

Reputation: 827

I've been using WyBuild to update my applications (including Windows services) and it's pretty awesome. Really easy to use, and really easy to integrate with existing applications. It's a pretty great Automatic Updating framework...

http://wyday.com/wybuild/help/automatic-updates/windows-services-console-apps.php http://wyday.com/wybuild/help/silent-update-windows-service.php

Note that it is a paid framework (the licence is per developer, a free trial is included)

Upvotes: 3

gillonba
gillonba

Reputation: 917

In case anyone else is searching for this; I found this link interesting. I have not implemented this solution, but it looks like it might work for me

http://www.eggheadcafe.com/articles/20041204.asp

Upvotes: 1

David Basarab
David Basarab

Reputation: 73301

Another possible solution is to have a seperate service that runs, stops the other one, if there is an update, and then updates the service. You can't have a service update itself because the .dll that is running will not stop.

Seperating the business logic layer would be a good option. You could also rewrite the main service to run under reflection by a master or control service. This is similar to seperating the business logic, and it would just require stopping a thread and the starting it again.

I know of no known framework that does this. I have done this myself, but that is not a public framework.

Upvotes: 3

ilitirit
ilitirit

Reputation: 16352

I'm not aware of any Frameworks that facilitate solutions to this specific problem.

What you could try though is separating the business logic of the service from the actual service code into different assemblies. Have the service assembly check for updates to the business logic assembly at regular intervals, copy it from a remote source if necessary, unload the old BL assembly (and perhaps delete), and then dynamically load the new version (unloading the old assembly is not a trivial task).

Upvotes: 3

Esteban Araya
Esteban Araya

Reputation: 29664

Could you clarify your question a bit? I'm a bit confused, because as far as I know, you can always overwrite the DLLs the service uses. The copy and restart of the service can easily be made part of you build process.

Upvotes: -4

Related Questions