.Net core 2.0 console app as a windows service

Matthew P. picture Matthew P. · May 23, 2018 · Viewed 11.2k times · Source

I am trying to set up a .Net Core Console application as a service. Using .Net standard I usually make use of Topshelf but this does not seem to support .Net Core.

Since Topshelf is not an option what can I do to run the the .Net Core Console application as a Windows service?

I have come access https://github.com/PeterKottas/DotNetCore.WindowsService, is this a viable substitute for a production environment?

Answer

Martin Ullrich picture Martin Ullrich · May 23, 2018

There are a few options:

  1. Use the Windows Compatibility Pack which brings back ServiceBase and related APIs to .NET Core, so TopShelf may work out of the box. (the pack is in RC at the time of writing with scheduled stable release about a week away)

  2. TopShelf now supports .NET Core, based on the compatibility pack / windows compatibility for newer .NET Core versions.

  3. https://github.com/PeterKottas/DotNetCore.WindowsService seems to work for a lot of users so I suggest giving it a try.

  4. The library in (3) is a nice API around DasMulli.Win32.ServiceUtils which I wrote for our company to be able to deploy self-contained .NET Core Applications in production. So far we haven't had any problems.

  5. Other service hosts which abstract the windows service infrastructure and run arbitrary programs - such as the Non-Sucking Service Manager. Note that this may not give good ways to gracefully shut down in reaction to a Stop command.