我正在编写批处理文件以使用Visual C ++运行某些构建。我想"撤消" vsvars32.bat / vcvarsXX.bat在脚本结束时发生更改,以便在脚本运行之前保持环境不变。
示例1 - 使用vsvars32.bat
call %VS100COMNTOOLS%vsvars32.bat
devenv myProject.sln /Build "Debug|Win32"
:: Now undo vsvars32.bat
示例2 - 使用vcvars32.bat和vcvars64.bat
<path to VC bin>vcvars32.bat
:: cmd line build calls for 32 bit application
:: Now undo vcvars32.bat
<path to VC bin>amd64\vcvars64.bat
:: cmd line build calls for 64 bit application
:: Now undo vcvars64.bat
有什么建议吗?
答案 0 :(得分:10)
解决方案很简单 - SETLOCAL与ENDLOCAL结合使用。输入HELP SETLOCAL
或HELP ENDLOCAL
以获取有关使用情况的更多信息。
示例1:
setlocal
call %VS100COMNTOOLS%vsvars32.bat
devenv myProject.sln /Build "Debug|Win32"
endlocal
示例2:
setlocal
<path to VC bin>vcvars32.bat
:: cmd line build calls for 32 bit application
endlocal
setlocal
<path to VC bin>amd64\vcvars64.bat
:: cmd line build calls for 64 bit application
endlocal
答案 1 :(得分:1)
如果你的build.bat将被调用,那会更简单:
cmd.exe /c build.bat
这将:
因此,在当前环境中不会发生任何变化,也不需要进行清理。