通過函數實現sln下各個子工程的調用,函數的參數就是工程名,必須在sln中有,否則報錯;
_solution_file是解決方案名稱,log是編譯日志文件
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:buildPro - here starts my function identified by it's label
devenv %_solution_file% /build "Debug" /Project %1 /Out %_log%
if not %errorlevel% == 0 echo %_solution_file% failed! Error: %errorlevel% >>%_log%
if %errorlevel% == 0 echo %_solution_file% compiled successful >>%_log%
::If compile failed stop processing:
if not %errorlevel% == 0 exit
echo [%DATE% %Time%] %1 編譯完成
goto:eof
pause
echo "結束全編譯"
pause
這個bat示例如下:
@echo off
setlocal
set build=%1
set platform=%2
set build_config="%build%|%platform%"
rem set compile log
set _log="%~dp0CompileResultsAll.log"
rem del build log if the log is not empty
if exist %_log% (del %_log%)
rem 當前腳本所在路徑
set build_root = %~dp0
set work_path=%~dp0/NFMidWare
rem vcvarsall.bat所在的路徑:
set vcvars= "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvarsall.bat"
call %vcvars% x64
echo "開始所有目錄編譯"
rem 設置解決方案的路徑
set _solution_file="%~dp0/NoahFrameX.sln"
@echo %~dp0
echo =================編譯依賴庫===============
call:buildPro jemalloc
call:buildPro libevent
call:buildPro libevent_core
call:buildPro libprotobuf
call:buildPro Theron
echo ==================編譯基礎類庫===============
call:buildPro ActorPlugin
call:buildPro CommLib
echo ===================編譯業務==================
call:buildPro BattlePlugin
echo =====================編譯服務器==================
call:buildProFDataAgent_NosqlPlugin
call:buildPro GameLogicPlugin
pause
exit
::--------------------------------------------------------
::-- Function section starts below here
::--------------------------------------------------------
:buildPro - here starts my function identified by it's label
devenv %_solution_file% /build "Debug" /Project %1 /Out %_log%
if not %errorlevel% == 0 echo %_solution_file% failed! Error: %errorlevel% >>%_log%
if %errorlevel% == 0 echo %_solution_file% compiled successful >>%_log%
::If compile failed stop processing:
if not %errorlevel% == 0 exit
echo [%DATE% %Time%] %1 編譯完成
goto:eof
pause
echo "結束全編譯"
pause
可以通過遍歷某個目錄,獲取工程文件名,在傳入上面所描述的函數中 獲取工程名方法如下:
@echo off
rem 文件夾路徑
set path=".\Server"
for /r %path% %%f in (*.vcxproj) do (
rem 完整路徑文件名
rem echo %%f
rem 文件名
echo %%~nf)
rem 文件擴展名
rem echo %%~xf)
pause