具体代码如下
使用管理员身份运行
@ECHO OFF
setlocal EnableDelayedExpansion
color 3e
title 添加服务配置
将启动目录设置为本文件存在的目录(不设置就会找不到发布文件)
PUSHD %~DP0 & cd /d "%~dp0"
%1 %2
mshta vbscript:createobject("shell.application").shellexecute("%~s0","goto :runas","","runas",1)(window.close)&goto :eof
:runas
pushd %~dp0
rem do something
popd
关闭网站应用(NK4.0 为网站名称)
c:\Windows\System32\inetsrv\appcmd.exe stop site "NK4.0"&
关闭网站应用池
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:NK4.0_BasicAppliction
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:NK4.0_BusinessSite
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:NK4.0_UIBuilder
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:NK4.0_UIViewer
C:\Windows\System32\inetsrv\appcmd.exe stop apppool /apppool.name:NK4.0_TestApplication
发布信息到发布文件夹下 -o 后边的为发布路径 具体信息请 -h 查看命令行帮助
dotnet publish BasicApplication -o ../publish/BasicApplication -c Debug&
dotnet publish BusinessSite -o ../publish/BusinessSite -c Debug&
dotnet publish UIBuilder -o ../publish/UIBuilder -c Debug&
dotnet publish UIViewer -o ../publish/UIViewer -c Debug&
dotnet publish TestApplication -o ../publish/TestApplication -c Debug
开启网站应用池
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:NK4.0_BasicAppliction
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:NK4.0_BusinessSite
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:NK4.0_UIBuilder
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:NK4.0_UIViewer
C:\Windows\System32\inetsrv\appcmd.exe start apppool /apppool.name:NK4.0_TestApplication
开启网站
c:\Windows\System32\inetsrv\appcmd.exe start site "NK4.0"
echo 发布完成,按任意键退出
pause >nul
exit
将上边的代码整理成bat文件放在项目所在文件夹下
例如我就放在WebApps文件夹下
然后执行bat文件
配置好之后就可以将配置的项目批量发布到IIS 了