.net6 core web项目发布部署到IIS,以Windows服务的形式部署启动,报错1053,报1067错误解决办法
安装NuGet包
Microsoft.Extensions.Hosting.WindowsServices
var builder = WebApplication.CreateBuilder(new WebApplicationOptions { ContentRootPath = AppContext.BaseDirectory, Args = args }); // Add services to the container. builder.Services.AddControllersWithViews(); builder.Host.UseWindowsService(); builder.WebHost.UseUrls("http://*:8029"); Directory.SetCurrentDirectory(AppContext.BaseDirectory);
在appsettings.json 增如下
"Kestrel": {
"Endpoints": {
"Http": { "Url": "http://*:8026" }
}
},
发布生成后
----------------------安装----------------------
set serviceName=TestTask114
set serviceFilePath="D:\m\publish\WebApplication3.exe"
set serviceDescription="测试任务"
sc create %serviceName% BinPath=%serviceFilePath%
sc config %serviceName% start=auto
sc config %serviceName% start=delayed-auto
sc description %serviceName% %serviceDescription%
sc failure %serviceName% reset= 0 actions= restart/1200000
sc start %serviceName%
pause
----------------------卸载----------------------
set serviceName=TestTask11
sc stop %serviceName%
sc delete %serviceName%
pause