.Net core 2.0 console app as a windows service

11,424

Solution 1

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.

Solution 2

In .net core you do not have the option to run as Service. However, if you containerize your console application you can deploy the container anywhere and it is just the same as running as a service. From .NET Core 2.1 on you are able to use the Host and HostBuilder to manage DI, Logging, Graceful shut down, etc in you console app. Have a look at:

Hosting services in .NET Core console application

Share:
11,424
Matthew P.
Author by

Matthew P.

Updated on July 24, 2022

Comments

  • Matthew P.
    Matthew P. almost 2 years

    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?

  • Matthew P.
    Matthew P. almost 6 years
    Thanks, will await the stable release mentioned in 1
  • Martin Ullrich
    Martin Ullrich almost 6 years
    You can already go ahead using the 2.1.0 RTM early access github.com/aspnet/Home/wiki/2.1.0-Early-Access-Downloads
  • LearningNeverEnds
    LearningNeverEnds over 5 years
    Update: Topshelf now supports core.