使用bat脚本编译VS工程

    一直以为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!  *****************************


你可能感兴趣的:(使用bat脚本编译VS工程)