简体   繁体   中英

.Net core 2.0 console app as a windows service

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?

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. (the pack is in RC at the time of writing with scheduled stable release about a week away)

  2. TopShelf now supports .NET Core, based on the compatibility pack / windows compatibility for newer .NET Core versions.

  3. https://github.com/PeterKottas/DotNetCore.WindowsService seems to work for a lot of users so I suggest giving it a try.

  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. 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 . 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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