使用bat脚本编译VS工程

本文介绍如何使用devenv.exe通过命令行进行编译,并提供了一个实际项目的编译脚本示例,该脚本能够自动化编译多个解决方案并进行文件打包。

    一直以为devenv.exe是个gui编译工具,没想到还支持命令行下编译。命令行形式如下:

    devenv.exe 解决方案名.sln /rebuild "平台(Win32/x64)|配置(Debug/Release)"

    例如,我在C盘下有个名为test的解决方案,要编译出x86/x64平台的Debug/Release,一共4种类型的代码。那可以在test解决方案的同层目录下建立一个编译脚本,之后双击运行等待编译完成即可:

set devnev="C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"
%devnev% %cd%\bld.sln /rebuild "Debug|win32"
%devnev% %cd%\bld.sln /rebuild "Debug|x64"
%devnev% %cd%\bld.sln /rebuild "Release|win32"
%devnev% %cd%\bld.sln /rebuild "Release|x64"

    当然,这并不比直接在IDE中编译方便多少。最后贴出一个项目中用到的脚本

@echo **************************************************
@echo *                                                *
@echo *                System Driver                   *
@echo *                                                *
@echo **************************************************
@rem Set Project Path
@set Current_path = %cd%
@Set BtMon_Path = %cd%/Toshiba_System_Driver/BtMon_SystemDriver_0725
@Set RMService_path =
@Set TabSysSvc_path =
@Set tosrfec_path =
@Set TosSysHID_path =
@Set TVALZ_path =
@Set TosQnt_path =
@Set VS2010_BuildTool_path = "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"

@echo === Starting to Build System Driver for WinXP Win8 Win10 ===
@echo 1.Building BtMon......
@devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\BtMon\BtMon\BtMon.sln /rebuild "release|Win32"
@rem devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\BtMon\BtMon\BtMon.sln /rebuild "release|Win32" /out "C:\Test-build\BuildLog.txt"

@devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\BtMon\BtMon4\BtMon2.sln /rebuild "release|Win32"
@devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\BtMon\BtMon4\BtMon2.sln /rebuild "release|x64"

@devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\DrvInst\DrvInst.sln /rebuild "release|Win32

@devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\TosBthSupport_ForMSStack\TosBthSupport_ForMSStack.sln /rebuild "release|Win32"
@devenv.exe %cd%\BtMon_SystemDriver_0725\BtMon\TosBthSupport_ForMSStack\TosBthSupport_ForMSStack.sln /rebuild "Release|x64"

@echo 2.Building RMService......
@devenv.exe %cd%\RMService\RMService.sln /rebuild "Win8.1 Release|Win32"
@devenv.exe %cd%\RMService\RMService.sln /rebuild "Win8.1 Release|x64"

@echo 3.Building TabSysSvc......
@devenv.exe "%cd%\Tablet_System_Service\trunk\(Released)TOSTABSYSSVCINST_20130228a\TOSTABSYSSVCINST.sln" /rebuild "release|Win32"
@rem devenv.exe "%cd%\Tablet_System_Service\trunk\(Released)TOSTABSYSSVCINST_20130228a\TOSTABSYSSVCINST.sln" /rebuild "release|x64"
@devenv.exe %cd%\Tablet_System_Service\trunk\TOSTABSYSSVC_Config_version\TOSTABSYSSVC.sln /rebuild "release|Win32"
@devenv.exe %cd%\Tablet_System_Service\trunk\TOSTABSYSSVC_Config_version\TOSTABSYSSVC.sln /rebuild "release|x64"

@echo 4.Building Tosrfec......
@devenv.exe %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\tosrfec.sln /rebuild "Win8 Release|Win32" 
@devenv.exe %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\tosrfec.sln /rebuild "Win8 Release|x64" 

@echo 5.Building TosSysHID......
@devenv.exe %cd%\TosSysHID\C++\TosHidSysRadioSwitch.sln /rebuild "Win8 beta Release|Win32" 
@devenv.exe %cd%\TosSysHID\C++\TosHidSysRadioSwitch.sln /rebuild "Win8 beta Release|x64" 

@echo 6.Building TVALZ......
@devenv.exe "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win7\TVALZ_Win8\TVALZ_Win7.sln" /rebuild "Win8 Release|Win32"
@devenv.exe "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win7\TVALZ_Win8\TVALZ_Win7.sln" /rebuild "Win8 Release|x64"
@devenv.exe "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\TVALZ_Win8.sln" /rebuild "Win8 Release|Win32"
@devenv.exe "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\TVALZ_Win8.sln" /rebuild "Win8 Release|x64"

@echo 7.Building TosQnt......
@rem This project need VS2010
@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe" %cd%\quick-note-taking_trunk\TosQntExe\TosQntExe.sln /rebuild "release|Win32"

@echo 8.Making DIR for Package......
@md %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@md %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64
@md %cd%\SystemDriver-WaitForSign\BtMon\DriverXP\x64
@md %cd%\SystemDriver-WaitForSign\RMService\x86
@md %cd%\SystemDriver-WaitForSign\RMService\x64
@md %cd%\SystemDriver-WaitForSign\TabSysSvc\32bit
@md %cd%\SystemDriver-WaitForSign\TosQnt

@echo 9.Copying Files to Package DIR......
@xcopy %cd%\BtMon_SystemDriver_0725\BtMon\bin\*.* %cd%\SystemDriver-WaitForSign\BtMon

@xcopy %cd%\quick-note-taking_trunk\TosQntExe\Release\TosQntExe.exe %cd%\SystemDriver-WaitForSign\TosQnt

@xcopy %cd%\RMService\Win8.1Release\RMService.exe %cd%\SystemDriver-WaitForSign\RMService\x86
@xcopy %cd%\RMService\x64\Win8.1Release\RMService.exe %cd%\SystemDriver-WaitForSign\RMService\x64

@xcopy %cd%\Tablet_System_Service\trunk\TOSTABSYSSVC_Config_version\Release\TOSTABSYSSVC.exe %cd%\SystemDriver-WaitForSign\TabSysSvc\32bit
@xcopy %cd%\Tablet_System_Service\trunk\TOSTABSYSSVC_Config_version\x64\Release\TOSTABSYSSVC.exe %cd%\SystemDriver-WaitForSign\TabSysSvc\
@xcopy "%cd%\Tablet_System_Service\trunk\(Released)TOSTABSYSSVCINST_20130228a\Release\TOSTABSYSSVCINST.exe" %cd%\SystemDriver-WaitForSign\TabSysSvc\

@xcopy %cd%\TosSysHID\C++\Win8betaRelease\Thotkey.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1
@xcopy %cd%\TosSysHID\C++\Win8betaRelease\Thotkey.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10
@rem @xcopy %cd%\TosSysHID\C++\Win8betaRelease\Thotkey.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1
@rem @xcopy %cd%\TosSysHID\C++\Win8betaRelease\Thotkey.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10
@xcopy %cd%\TosSysHID\C++\x64\Win8betaRelease\Thotkey.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@xcopy %cd%\TosSysHID\C++\x64\Win8betaRelease\Thotkey.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64
@rem @xcopy %cd%\TosSysHID\C++\x64\Win8betaRelease\Thotkey.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@rem @xcopy %cd%\TosSysHID\C++\x64\Win8betaRelease\Thotkey.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64

@xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x32\Tosrfec.sys %cd%\SystemDriver-WaitForSign\BtMon\DriverXP
@xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x32\Tosrfec.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1
@xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x32\Tosrfec.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10
@rem @xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x32\Tosrfec.inf %cd%\SystemDriver-WaitForSign\BtMon\DriverXP
@rem @xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x32\Tosrfec.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1
@rem @xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x32\Tosrfec.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10
@xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x64\Tosrfec.sys %cd%\SystemDriver-WaitForSign\BtMon\DriverXP\x64
@xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x64\Tosrfec.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x64\Tosrfec.sys %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64
@rem @xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x64\Tosrfec.inf %cd%\SystemDriver-WaitForSign\BtMon\DriverXP\x64
@rem @xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x64\Tosrfec.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@rem @xcopy %cd%\tosrfec_1030_Newest\tosrfec_1030_Newest\tosrfec\bin\x64\Tosrfec.inf %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64

@xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1
@xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10

@rem @xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1
@rem @xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10

@xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\x64\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\x64\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64
@rem @xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\x64\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win8.1\x64
@rem @xcopy "%cd%\TVALZ_Source_New_0725\TVALZ_Source  New\Win10_Win8.1\TVALZ_Win8\x64\Win8Release\*.sys" %cd%\SystemDriver-WaitForSign\BtMon\Driver_Win10\x64          

@echo *********************  Done! Please check whether each file was built and copied, thanks!  *****************************


在Qt 5.14环境下使用bat脚本编译构建.pro工程,可参考以下步骤和示例脚本。 首先,需要设置Qt和编译器的环境变量,确保系统能够找到相应的工具。对于MinGW版本的Qt 5.14,bat脚本示例如下: ```batch :: 设置Qt环境变量 call "C:\Qt\Qt5.14.0\5.14.0\mingw73_64\bin\qtenv2.bat" :: 设置qmake和mingw32-make的路径 set QMAKE_PATH="C:\Qt\Qt5.14.0\5.14.0\mingw73_64\bin\qmake.exe" set MINGW_MAKE_PATH="C:\Qt\Qt5.14.0\Tools\mingw730_64\bin\mingw32-make.exe" :: 生成Makefile %QMAKE_PATH% your_project.pro :: 清理之前的编译结果 %MINGW_MAKE_PATH% clean :: 进行调试版本的编译 %MINGW_MAKE_PATH% debug :: 进行发布版本的编译 %MINGW_MAKE_PATH% release ``` 如果是MSVC版本的Qt 5.14,bat脚本示例如下: ```batch :: 设置Qt环境变量 call "C:\Qt\Qt5.14.0\5.14.0\msvc2017_64\bin\qtenv2.bat" :: 设置Visual Studio的环境变量 call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat" :: 设置qmake和nmake的路径 set QMAKE_PATH="C:\Qt\Qt5.14.0\5.14.0\msvc2017_64\bin\qmake.exe" set NMAKE_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx64\x64\nmake.exe" :: 生成Makefile %QMAKE_PATH% your_project.pro :: 清理之前的编译结果 %NMAKE_PATH% clean :: 进行调试版本的编译 %NMAKE_PATH% debug :: 进行发布版本的编译 %NMAKE_PATH% release ``` 请根据实际的Qt安装路径和编译器版本对上述脚本中的路径进行相应修改,将`your_project.pro`替换为实际的.pro工程文件名。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值