带有.NET Core的Windows服务 [英] Windows Service with .NET Core

查看:92
本文介绍了带有.NET Core的Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用.NET Core开发Windows服务(能够在启动时启动等...)?

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

我发现可以利用的所有教程和说明出于某种原因在Visual Studio 2015中找不到和添加System.ServiceProcess.ServiceBase吗?

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

我还尝试避免使用诸如SrvStart之类的第三方工具/库。诸如Topshelf之类的东西可以接受,但似乎不适用于.NET Core。

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.

如果该服务可以在Windows和Linux下运行,那就太好了。

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

有什么想法可以实现这一目标吗?

Any ideas how I could achieve this?

推荐答案

我' ll总结一些选项:

I'll summarise some options:


  1. 将您的代码移动到.NET Standard库中,并将其托管在.NET Framework应用程序中,这样您就可以使用 ServiceBase 。当然,这将需要在目标计算机上安装.NET Framework

  2. 使用 NSSM (非吮吸服务管理器)来管理.NET Core控制台应用程序(它具有公共域许可证)

  3. 使用Windows API调用来挂接Windows服务方法。这是 DotNetCore.WindowsService dotnet-win32-service (均已获得MIT许可)

  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)

这篇关于带有.NET Core的Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆