Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Service with .NET Core [closed]

Is there a way to develop a windows service (able to start on boot etc...) with .NET Core?

All tutorials and instructions I find utilize System.ServiceProcess.ServiceBase which can not be found and added for some reason in Visual Studio 2015?

I also try to avoid using 3rd party tools/libraries like SrvStart. Something like Topshelf would be acceptable but seems to be not available for .NET core.

And it would be great if the service could run under windows and linux.

Any ideas how I could achieve this?

like image 998
monty Avatar asked Dec 07 '16 10:12

monty


People also ask

Does .NET Core support Windows Service?

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.

Is .NET Core being discontinued?

NET 5.0 SDK versions will continue to be supported in VS 16.11 until December of 2022 when . NET Core 3.1 goes out of support so that . NET Core 3.1 customers can continue to use 16.11 to developer their applications.

What is Windows Service in .NET Core?

An ASP.NET Core app can be hosted on Windows as a Windows Service without using IIS. When hosted as a Windows Service, the app automatically starts after server reboots.


1 Answers

I'll summarise some options:

  1. Move your code into a .NET Standard library, and host it in a .NET Framework app, so you can use ServiceBase. This will of course need the .NET Framework to be installed on the target machine
  2. Use NSSM (the Non-Sucking Service Manager) to manage a .NET Core console app (it has a public domain license)
  3. Use Windows API calls to hook into Windows service methods. This is the approach taken by DotNetCore.WindowsService and dotnet-win32-service (both are MIT licensed)
like image 74
Cocowalla Avatar answered Oct 17 '22 02:10

Cocowalla