问题
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?
回答1:
I'll summarise some options:
- 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 - Use NSSM (the Non-Sucking Service Manager) to manage a .NET Core console app (it has a public domain license)
- 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)
来源:https://stackoverflow.com/questions/41014513/windows-service-with-net-core