Widnows bat 编译VS项目

来源:互联网 发布:少女漫画推荐 知乎 编辑:程序博客网 时间:2024/06/05 10:10
因为项目需要,有时候直接采用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 0
原创粉丝点击