Follow the official website tutorial
https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1&tabs= Aspnetcore2x
Copy the official demo code,
Https://github.com/aspnet/Docs/tree/master/aspnetcore/host-and-deploy/windows-service/sample
Create an ASP. NET Core MVC project. Release to d:\svc with release.
Then open PowerShell, enter command, error
SC create MyService binpath= "D:\svc\MvcService.exe"
Set-content: Could not find positional formal parameters that accept the actual parameter "Binpath=d:\svc\mvcservice.exe".
Location Line: 1 characters: 1
+ SC Create myservice binpath= "D:\svc\MvcService.exe"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ categoryinfo:invalidargument: (:) [Set-content],parameterbindingexception
+ Fullyqualifiederrorid:positionalparameternotfound,microsoft.powershell.commands.setcontentcommand
Feel strange, command and official website exactly the same, how is wrong? All kinds of tossing and shaking are uncertain.
Consider a traditional command prompt for the tools used on the official website, so change it. The latest version of WIN10, right click on the Start menu, there is no command prompt. Left-click Start menu, keyboard cmd, you can find the command prompt tool, at this time also with the right button, run as Administrator, very troublesome.
However, the service was successfully installed!
Visit http://localhost:5000 to see the Web page.
No words, I always think PowerShell is an upgrade of CMD, forward-compatible, did not expect this pit.
Finally, using SC delete MyService to delete the service, the discovery service is still in, just stopped and disabled. I don't know if it's right.
Hosting the pit of ASP. NET core in Windows services