.NET Core Windows Services with Topshelf

Jack Wild
2 min readApr 22, 2019

--

Topshelf is a great tool for creating Windows services in .NET. It solves the problem of having to reinstall a Windows service after every code change by producing an .exe file that runs as a console application.

This just works for full .NET framework applications as they always produce an .exe file. With .NET core apps however, by default they produce a .dll file.

To produce an .exe in .NET core, use the runtime identifier parameter when running dotnet publish to specify that the app will run on Windows. For example:

dotnet publish TopshelfDotNetCoreExample.csproj -r win10-x64

In the publish folder, an .exe file is created:

To install as a Windows service, run the following command from the publish directory:

TopshelfDotNetCoreExample.exe install

For an example project with .NET core 2.2 and Topshelf 4.2.0 see https://github.com/jackowild/TopshelfDotNetCoreExample

Note that in .NET core 3.0, the .NET team are creating a “worker service” application template which may mean Topshelf will no longer be necessary. See https://devblogs.microsoft.com/aspnet/net-core-workers-as-windows-services/

--

--