IIS方式:windows
1:iis配置netcore發佈的文件函數
2:iis設置運行庫無託管模式工具
3:安裝DotNetCore.1.0.4_1.1.1-WindowsHosting.exeui
4:安裝dotnet-hosting-2.2.2-win.exe命令行
https://dotnet.microsoft.com/downloadio
5:OKconsole
windows服務方式:配置
1:main函數入口修改位以下(安裝包文件:Microsoft.AspNetCore.Hosting.WindowsServices):List
#region
IWebHost host = WebHost.CreateDefaultBuilder(args)
.UseKestrel(options => { options.Listen(IPAddress.Any, 5201); }) //5201是我用的端口,你改爲本身的
.UseStartup<Startup>() //使用Startup配置類
.Build();
bool isService = !(Debugger.IsAttached || args.Contains("--console")); //Debug狀態或者程序參數中帶有--console都表示普通運行方式而不是Windows服務運行方式
if (isService)
{
host.RunAsService();
}
else
{
host.Run();
}
#endregionfile
2:配置服務
以管理員身份運行命令行工具,輸入以下:
建立服務
sc create MyServiceName binPath= "\"C:\program files\dotnet\dotnet.exe\" \"D:\Services\MyService.dll(程序發佈包裏的主文件地址)\"" DisplayName= "MyServiceName" start= auto
啓動服務
sc run MyServiceName
中止服務
sc stop MyServiceName
卸載服務
sc delete MyServiceName