title: Set up Visual Studio command line build environment with python
body: <p>I want to set up Visual Studio command line build environment with python so that I can use</p>
  
  <p><code>subprocess.call(['msbuild', 'myapp.sln /p:Configuration=Release'])</code></p>
  
  <p>to build my project with automation.</p>
  
  <p>I have some other dependencies need to use a portable scripting language, so I chose python.</p>
  
  <p>Is there any ways to do so? Thanks in advance.</p>
  
  <hr>
  
  <p>Trial 1 (failure):</p>
  
  <p>I tried to call <code>vcvarsall.bat</code> in python. However, it seems that it did not actually setup the environment for me.</p>
  
  <pre><code>import os
  import subprocess
  
  # Backup current environment vars
  envvar_backup_list = [
      'CMAKE_PREFIX_PATH',
      'PATH'
  ]
  
  envvar_backup_val_list = []
  
  for i in envvar_backup_list:
      envvar_backup_val_list.append(os.environ.get(i, None))
  
  # Set CMAKE environment vars
  os.environ['CMAKE_PREFIX_PATH'] = 'C:\\Qt\\Qt5.3.1\\5.3\\msvc2013_64\\lib\\cmake\\'
  
  # Set MSVC environment path
  current_path = os.getcwd()
  os.chdir('C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\')
  ret = subprocess.call(['vcvarsall.bat', 'amd64'], shell=True)
  os.chdir(current_path)
  
  subprocess.call(['msbuild'], shell=True)
  subprocess.call(['cl.exe'], shell=True)
  </code></pre>