Is is possible to host a ASP.NET Core 2 Web API NET Core 2 application in Windows Service targeting

狂风中的少年 提交于 2019-12-24 06:35:24

问题


I have a ASP.NET Core Web Web Api application targeting netcoreapp2.0.

I want to host the Kestrel server inside a Windows Service.

The examples I've seen like this one https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/windows-service?tabs=aspnetcore2x are for Core Web API running on .NET Framework 4.6.1.

How can I host my application in a Windows Service but still target netcoreapp2.0?


回答1:


It is possible to host a .Net Core 2 Kestrel server inside a Windows service but you have to use the nssm. Nssm is a tool that makes it easy to turn a .net core application in to a service.

It even allows you to send a CTRL-C message from the service when it shuts down. This is important because Core doesn't currently support the traditional OnStart and OnStop messages from Windows services.

Point nssm toward a batch or cmd file that starts your application. All you need for that is a one liner like -

dotnet myApplication.dll

Nssm will add that to your Windows services.

See Hosting a .NET Core 2 Kestrel Server in a Windows Service for full details.



来源:https://stackoverflow.com/questions/49457156/is-is-possible-to-host-a-asp-net-core-2-web-api-net-core-2-application-in-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!