Benjamin

静以修身,俭以养德,非澹薄无以明志,非宁静无以致远。
随笔 - 388, 文章 - 0, 评论 - 196, 引用 - 0
数据加载中……

vs2017命令行编译sln或vcxproj文件

通过函数实现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

posted on 2018-01-24 09:31 Benjamin 阅读(7973) 评论(0)  编辑 收藏 引用 所属分类: VC


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理