狗屎花,目连大叫,兰陵缭乱第二部
sdk 2.1.300
1、添加运行标识符
xml <propertygroup> <targetframework>netcoreapp2.1</targetframework> <runtimeidentifier>win7-x64</runtimeidentifier> </propertygroup>
2、添加包引用 dotnet add package microsoft.aspnetcore.hosting.windowsservices -v 2.1.0 -s
3、确认导入是否成功
xml <itemgroup> <packagereference include="microsoft.aspnetcore.app" /> <packagereference include="microsoft.aspnetcore.hosting.windowsservices" version="2.1.0" /> </itemgroup>
4、修改program main 函数
public static void main(string[] args) { createwebhostbuilder(args).build().runasservice(); } public static iwebhostbuilder createwebhostbuilder(string[] args) { var pathtoexe = process.getcurrentprocess().mainmodule.filename; var pathtocontentroot = path.getdirectoryname(pathtoexe); return webhost.createdefaultbuilder(args) .usekestrel() .useurls("http://*:5001", "http://*:5002") .configureappconfiguration((context, config) => { // configure the app here. }) .usecontentroot(pathtocontentroot) .usestartup<startup>(); }
5、发布运行
dotnet publish -c release -o "f:\winservices\mvcapp21"
6、使用sc.exe工具创建服务 此处使用系统原始dos命令
发布根目录下:sc create mvcapp21 binpath= "f:\winservices\mvcapp21\mvcapp21.exe"
确保 binpath= 参数与其值之间存在空格
启动服务 sc start myservice
查看服务状态 sc query myservice
停止服务 sc stop myservice
删除服务 sc delete myservice
7、可能遇到的问题
8、.net core 部署服务其他方案
9、回顾.net 部署服务
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Blazor server side 自家的一些开源的, 实用型项目的进度之 CEF客户端
.NET IoC模式依赖反转(DIP)、控制反转(Ioc)、依赖注入(DI)
vue+.netcore可支持业务代码扩展的开发框架 VOL.Vue 2.0版本发布
网友评论