用批处理批量编译多个解决方案(.sln)
-
批处理编译解决方案(.sln)
@echo off path %SYSTEMROOT%\Microsoft.NET\Framework64\v4.0.30319\ echo 正在生成HelloWorld项目,Build日志输出到HelloWorld.log.txt msbuild.exe ..\MyProjects\HelloWorld\HelloWorld.sln /t:Rebuild /p:Configuration=Release /p:VisualStudioVersion=12.0 /l:FileLogger,Microsoft.Build.Engine;logfile=.\HelloWorld.log.txt echo 编译完成 pause>nul&exit /b REM exit /b参数表示退出当前批处理,而不是退出cmd.exe
-
批处理批量编译解决方案(.sln)[Build_Core.bat]
@echo off IF "%1"=="" ( echo 没有指定项目列表文件 echo 按任意键退出 pause exit ) ELSE ( echo 项目列表:%1 echo ____________ echo 正在开始编译 pause ) SET LogDir=logs_default IF NOT "%2"=="" ( IF EXIST %2 ( rd /s /q %2 ) SET LogDir=%2 ) mkdir %LogDir% REM 备份path(如不备份,后面使用其他系统命令,如find,会找不到) set originalPath=%path% path %SYSTEMROOT%\Microsoft.NET\Framework64\v4.0.30319\ SET MSBuild_Params=/t:Rebuild /p:Configuration=Release /p:VisualStudioVersion=12.0 /l:FileLogger,Microsoft.Build.Engine;logfile=.\%LogDir%\ FOR /F "eol=#" %%i in (%1) do ( for /F "usebackq delims=[]" %%I in (`echo %cd%\%%i`) do echo.正在生成%%~nxI for /F "usebackq delims=[]" %%I in (`echo %cd%\%%i`) do ( msbuild.exe %%i %MSBuild_Params%%%~nxI.log.txt ) REM %%~nxI是文件名带后缀(file.sln) ) echo 所有项目完毕,编译日志见%LogDir% REM 还原path path %originalPath% pause REM ----------日志分析---------- REM 日志分析是根据Build日志里会有一行是“14 Error(s)”这样的字样(英文版VS,中文版需要修改关键字) echo 开始分析日志 cls cd %LogDir% find /n " Error(s)" *.log.txt cd ..
-
调用Build_Core.bat
Start_Build.bat@echo off set logDir=logs_Projects_All call Build_Core.bat Projects_All.txt %logDir% pause
Projects_All.txt (也可以使用绝对路径)
..\..\Solution001.sln ..\..\Solution002.sln ..\..\Solution003.sln ..\..\Solution004.sln ..\..\Solution005.sln ..\..\Solution006\Project001.Web.csproj
-
路径信息获取
REM 文件名获取 FOR /F "eol=#" %%I in (001_Projects.txt 001_Projects.txt) do ( echo %%~fI REM 完全路径 echo %%~xI REM 后缀 echo %%~nI REM 文件名不带后缀 )
-
用goto实现循环
set count=1 :continue set /a count+=1 if %count% lss 10 ( echo %count% goto continue )
-
to be continue...
如果你觉得这篇文章对你有帮助或者使你有所启发,请点击右下角的推荐按钮,谢谢,:)