Widnows bat 编译VS项目

因为项目需要,有时候直接采用bat文件编译整个项目,有很好的工具可用,就是devenv.

http://msdn.microsoft.com/en-us/library/a4sf02ac.aspx


根据msdn说明和不计其数的帖子,可以很容易写出自己的批处理命令文件。
///设置要调用的devenv路径
set _devenv="%VS110COMNTOOLS%..\..\Common7\IDE\devenv.com"
///设置log文件名和路径
set _log="%~dp0compileResults.log"
///当前路径--%~dp0表示当前的bat文件所在的路径,此处是为了获取PARENT路径
set Directory= %~dp0
set Directory=%Directory:~0,-1%
for %%d in (%Directory%) do set ParentDirectory=%%~dpd
echo [�TE% %Time%] Start compile sequence >%_log% 
::echo Used compile configuration is %buildAnyCPU% >>%_log% 
set _solution_files="%ParentDirectory%test.sln"
echo _solution_files
set _project_file="%~dp0test.vcxproj" 
rem Start Debug Mode compile************************************************ 
///设置编译参数,相当于项目中的宏定义,从而实现根据不同的宏编译出不同的输出文件
此处类似于宏定义 #define PREFEFINETEST
///cl的用法参考msdn
set CL=/DPREDEFINETEST
echo %CL%
del %ParentDirectory�bug\*.*
%_devenv% %_solution_files% /build "Debug|Win32" /project %_project_file%   /Out %_log% 
if not %errorlevel% == 0 echo %_project_file% failed!   Error: %errorlevel% >>%_log% 
if %errorlevel% == 0     echo %_project_file% compiled successful >>%_log% 
rem If compile failed stop processing: 
::if not %errorlevel% == 0 pause 
::following code just get the parent path,to be changed 
echo [�TE% %Time%] Finished Debug compile sequence >>%_log%
///重新命名 
ren %ParentDirectory�bug\test.dll  testsuccess.dll
ren %ParentDirectory�bug\test.lib  testsuccess.lib
ren %ParentDirectory�bug\test.exp  testsuccess.exp
ren %ParentDirectory�bug\test.ilk    testsuccess.ilk
ren %ParentDirectory�bug\test.pdb  testsuccess.pdb
set CL=
echo %CL%
%_devenv% %_solution_files%  /build "Debug|Win32" /project %_project_file% /Out %_log% 
if not %errorlevel% == 0 echo %_project_file% failed!   Error: %errorlevel% >>%_log% 
if %errorlevel% == 0 echo %_project_file% compiled successful >>%_log% 
rem If compile failed stop processing: 
::if not %errorlevel% == 0 pause 
::following code just get the parent path,to be changed 
echo [�TE% %Time%] Finished Debug compile sequence >>%_log%
 
pause
链接:
获取parent 路径:
http://wiert.me/2011/08/09/batch-files-getting-directory-and-parent-directory/
http://jonausten.info/2011/11/02/windows-batch-file-find-parent-folder-name/
关于devenv的使用:
http://blog.sina.com.cn/s/blog_6234a2f00100fku8.html
CL的用法:
http://msdn.microsoft.com/zh-cn/library/kezkeayy.aspx
注意: 设置完之后如果需要取消 则直接
set CL=
即不赋值即可.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值