title: How to create a Simple Build Script for Visual Studio from the Command Line?
body: <p>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.</p>
  
  <p>I am able to manually build a solution by starting up the <code>Visual Studio Command Prompt</code> (which is just a command-line instance with the following command executed</p>
  
  <p><code>"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86</code></p>
  
  <p>After which I then build the project by calling: </p>
  
  <p><code>devenv "path\to\solutionFile\projectSolution1.sln" /build Debug</code></p>
  
  <p>This will build the project (assuming the project does not have errors) and I rinse and repeat for each project I want built.</p>
  
  <p><strong>However</strong> when I have the following in a batch file called <code>build.bat</code>:</p>
  
  <pre><code>"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86  
  echo "Starting Build for all Projects with proposed changes" 
  echo . 
  devenv "path\to\solutionFile\projectSolution2.sln" /build Debug
  devenv "another\path\to\solutionFile\projectSolution3.sln" /build Debug
  devenv "yet\another\path\to\solutionFile\projectSolution4.sln" /build Debug
  echo "All builds completed."
  pause
  </code></pre>
  
  <p><strong>The batch script only executes the first line</strong>, and waits until I type in <code>exit</code> 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 <code>cmd</code> actually invokes another instance of itself that executes <code>vcvarsall.bat</code> to set up the build environment. </p>
  
  <p>This will not work as typing <code>exit</code> kills that instance with <code>devenv</code> set up and the commands after that cannot execute as <code>devenv</code> is not a recognized command (since the exported path will not exist anymore)</p>
  
  <p><strong>In short</strong>, how can this be achieved (passing in the rest of the commands to the cmd instance with <code>devenv</code> 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. </p>