使用CMD命令部署.NetCore程序到IIS
dotnet restore cd src\XXXXX md publish dotnet publish -o publish cd publish set siteFilePath=%cd% set name="TEST" set siteHost="8888" cd C:\Windows\System32\inetsrv C: appcmd stop site /site.name:%name% appcmd stop AppPool /AppPool.name:%name% appcmd delete site /site.name:%name% appcmd delete AppPool /AppPool.name:%name% appcmd add AppPool /name:%name% /managedRuntimeVersion:"" appcmd add site /name:%name% /applicationDefaults.applicationPool:%name% /bindings:http/*:%siteHost%: /physicalPath:"%siteFilePath%" appcmd start site %name%
::git代码目录 set WORKSPACE="E:\Code" ::应用程序池 set APP_POOL_NAME="ProjectSite_Pool" ::站点 set SITE_NAME="ProjectSite" ::环境变量(appsettings.Production.json) set ASPNETCORE_ENVIRONMENT="Production" ::健康检查地址 set HEALTH_CHECK_URL="http://127.0.0.1:5000" echo 正在编译 dotnet publish "%WORKSPACE%\src\Project.Web.Host" -c Debug -o "%WORKSPACE%\publish" echo 正在停止应用程序池 c:\Windows\System32\inetsrv\appcmd.exe stop apppools "%APP_POOL_NAME%" echo 正在停止站点 c:\Windows\System32\inetsrv\appcmd.exe stop sites "%SITE_NAME%" echo 正在清理站点环境配置 c:\Windows\System32\inetsrv\appcmd.exe clear config "%SITE_NAME%" -section:system.webServer/aspNetCore /commit:apphost echo 正在设置站点环境配置 c:\Windows\System32\inetsrv\appcmd.exe set config "%SITE_NAME%" -section:system.webServer/aspNetCore /+"environmentVariables.[name='ASPNETCORE_ENVIRONMENT',value='%ASPNETCORE_ENVIRONMENT%']" /commit:apphost echo 正在发布站点 xcopy /e /c /y "%WORKSPACE%\publish" "F:\Site\" echo 正在启动站点 c:\Windows\System32\inetsrv\appcmd.exe start sites "%SITE_NAME%" echo 正在启动应用程序池 c:\Windows\System32\inetsrv\appcmd.exe start apppools "%APP_POOL_NAME%" echo 正在清理发布目录 del /a /s /q /f "%WORKSPACE%\publish" echo 发布完成 echo 正在点火 powershell curl -URi '%HEALTH_CHECK_URL%' -Method Get -UseBasicParsing if errorlevel 1 exit /b 0 echo 点火完成
相关链接: