按照官網教程git
https://docs.microsoft.com/zh-cn/aspnet/core/host-and-deploy/windows-service?view=aspnetcore-2.1&tabs=aspnetcore2xgithub
複製官方DEMO代碼,windows
https://github.com/aspnet/Docs/tree/master/aspnetcore/host-and-deploy/windows-service/sample工具
建立Asp.Net Core MVC項目。以release發佈到d:\svc。3d
而後打開PowerShell,輸入命令,報錯blog
sc create MyService binPath="D:\svc\MvcService.exe"教程
Set-Content : 找不到接受實際參數「binPath=D:\svc\MvcService.exe」的位置形式參數。get
所在位置 行:1 字符: 1cmd
+ sc create MyService binPath="D:\svc\MvcService.exe"it
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Content],ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand
以爲匪夷所思,命令跟官網如出一轍,怎麼就不對呢?各類折騰都搞不定。
考慮到官網用的工具是傳統的命令提示符,因此換一下。最新版的Win10,右鍵點擊開始菜單,已經沒有命令提示符。左鍵點開始菜單,鍵盤打cmd,能夠找到命令提示符工具,此時還要用右鍵,以管理員身份運行,很是麻煩。
然而居然成功安裝了服務!
訪問http://localhost:5000能夠看到網頁。
真是無語了,我一直認爲PowerShell就是CMD的升級版,向前兼容的,沒想到還有這種坑。
最後用sc delete MyService刪除服務,發現服務還在,只是中止和禁用了。也不知道對不對。