简体   繁体   中英

Net core 2.0 install windows service

After installing nuget package Microsoft.AspNetCore.Hosting.WindowsServices 2.0 It is not working because this package was created only for 4.6.1

I was install 2.1.0-preview2-final.

Ok, with host.RunAsService() it is compiling but not working when I start it via cmd And I have this message:

Cannot start service from the command line or a debugger. A Windows Service must first be installed and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.

How to install my project as a Windows Service?

This post Is is possible to host a ASP.NET Core 2 Web API NET Core 2 application in Windows Service targeting do not helps me.

And it is 3rd part tool, it is overhead.

You can use PowerShell to install your windows service. Just open an elevated powershell prompt, cd into the folder where your .net core service executable is, and type:

sc.exe create "My Service" binPath= (Resolve-Path .\MyService.exe)

I always make a self-contained deployment package for my .net core services, so I just zip the published folder, copy it to the target server, unzip it, then install it as above. After this My Service service should show up in the Services MMC SnapIn, from where you can start it, or staying in PowerShell you can start it by:

Start-Service -Name "My Service"

Hope this helps!

I found a solution.

I was update net core to 2.1, then I am publish my app as a portable for x86. After publish in path was a exe!!! Then I was start cmd line

SC create [Name] binpath="[pathtoexe\app.exe]"

And then I started like ordinary windows service.

PROFIT!!!

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