问题
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