I have a lot of Visual Studio Project Solutions in multiple directories (all with the extension .sln) and I want to write a simple batch script that will automatically build all solutions listed in the batch file.
I am able to manually build a solution by starting up the Visual Studio Command Prompt
(which is just a command-line instance with the following command executed
"%comspec%" /k "C:Program FilesMicrosoft Visual Studio 10.0VCvcvarsall.bat" x86
After which I then build the project by calling:
devenv "pathosolutionFileprojectSolution1.sln" /build Debug
This will build the project (assuming the project does not have errors) and I rinse and repeat for each project I want built.
However when I have the following in a batch file called build.bat
:
"%comspec%" /k "C:Program FilesMicrosoft Visual Studio 10.0VCvcvarsall.bat" x86
echo "Starting Build for all Projects with proposed changes"
echo .
devenv "pathosolutionFileprojectSolution2.sln" /build Debug
devenv "anotherpathosolutionFileprojectSolution3.sln" /build Debug
devenv "yetanotherpathosolutionFileprojectSolution4.sln" /build Debug
echo "All builds completed."
pause
The batch script only executes the first line, and waits until I type in exit
before executing the others. My understanding of this based on the research I have done on batch files and all the StackOverflow questions is that cmd
actually invokes another instance of itself that executes vcvarsall.bat
to set up the build environment.
This will not work as typing exit
kills that instance with devenv
set up and the commands after that cannot execute as devenv
is not a recognized command (since the exported path will not exist anymore)
In short, how can this be achieved (passing in the rest of the commands to the cmd instance with devenv
defined) in a single batch file? I understand this isn't a robust way (and there are a lot of tools that do this) of invoking builds but I'm just hoping to have one batch script to automate the manual work of individually calling these projects.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…