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