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?
NET Windows apps that can run as console apps or as Windows Services. You can quickly hook up events such as your service Start and Stop events, configure using code e.g. to set the account it runs as, configure dependencies on other services, and configure how it recovers from errors.
NET Core and . NET 5+, developers who relied on . NET Framework could create Windows Services to perform background tasks or execute long-running processes. This functionality is still available and you can create Worker Services that run as a Windows Service.
There are a few options:
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)
TopShelf now supports .NET Core, based on the compatibility pack / windows compatibility for newer .NET Core versions.
https://github.com/PeterKottas/DotNetCore.WindowsService seems to work for a lot of users so I suggest giving it a try.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With