简体   繁体   English

.Net core 2.0控制台应用程序作为Windows服务

[英].Net core 2.0 console app as a windows service

I am trying to set up a .Net Core Console application as a service. 我正在尝试将.Net Core Console应用程序设置为服务。 Using .Net standard I usually make use of Topshelf but this does not seem to support .Net Core. 使用.Net标准我通常使用Topshelf,但这似乎不支持.Net Core。

Since Topshelf is not an option what can I do to run the the .Net Core Console application as a Windows service? 由于Topshelf不是一个选项,我可以做什么来运行.Net Core Console应用程序作为Windows服务?

I have come access https://github.com/PeterKottas/DotNetCore.WindowsService , is this a viable substitute for a production environment? 我来访问https://github.com/PeterKottas/DotNetCore.WindowsService ,这是生产环境的可行替代品吗?

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. 使用Windows兼容包ServiceBase和相关API带回.NET Core,因此TopShelf可以开箱即用。 (the pack is in RC at the time of writing with scheduled stable release about a week away) (在写作时,包装在RC中,预定稳定释放大约一周之后)

  2. TopShelf now supports .NET Core, based on the compatibility pack / windows compatibility for newer .NET Core versions. TopShelf现在支持.NET Core,基于兼容性包/ Windows兼容性,适用于较新的.NET Core版本。

  3. https://github.com/PeterKottas/DotNetCore.WindowsService seems to work for a lot of users so I suggest giving it a try. https://github.com/PeterKottas/DotNetCore.WindowsService似乎适用于很多用户,因此我建议尝试一下。

  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. (3)中的库是围绕DasMulli.Win32.ServiceUtils的一个很好的API,我为公司编写了能够在生产中部署自包含.NET Core应用程序的API。 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 . 其他服务主机抽象Windows服务基础结构并运行任意程序 - 例如非吸引服务管理器 Note that this may not give good ways to gracefully shut down in reaction to a Stop command. 请注意,这可能无法为响应Stop命令而优雅地关闭。

In .net core you do not have the option to run as Service. 在.net核心中,您无法选择以服务身份运行。 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. 从.NET Core 2.1开始,您可以使用Host和HostBuilder在您的控制台应用程序中管理DI,Logging,Graceful关闭等。 Have a look at: 看一下:

Hosting services in .NET Core console application .NET Core控制台应用程序中的托管服务

在我们公司,我们使用非吸吮服务管理器 ,到目前为止,我没有任何问题,你可能想看看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM