Building and Debugging Windows Services with Topshelf

Windows Services made simple with Topshelf

Shems Eddine
SHEMSEDDINE on Code

--

What is Topshelf?

Topshelf is an open source Windows Service framework for the .NET platform that simplifies the way you develop, install and debug your Windows Services.

Debugging Windows Services isn’t easy to setup, and most likely, you will be implementing an ad-hoc solution for debugging them.

Ideally, what I want is to load up the project, hit F5 and I have the service running that I’m able to debug.

Windows Service running as a console application in debug

… and that is when Topshelf comes in.

Prerequisites:

  • Visual Studio
  • .NET Framework
  • Knowledge of C#

We will start off with the AwesomeService code base found here.

AwesomeService.Core is where you will have all of your IOC and the entry point of the application. The AppRunner.cs has two function, start, for construction and stop, for destruction of the application.

The AwesomeService.WindowsService project is just an ordinary console application that starts the app runner and blocks until the app runner stops (at the moment it will not stop until you kill the window).

--

--

Shems Eddine
SHEMSEDDINE on Code

Azure Cloud Platform Expert | NodeJS & .NET Senior Consultant | Startup CTO in City of London