title: Execute msbuild from ant after lanching vcvarsall.bat
body: <p>Good morning,
  I'm trying to compile a C++ project with Ant using the VS2008 compiler (msbuild). 
  This is my sequence of operation:</p>
  
  <p><code>&lt;target name="setEnv" &gt;
          &lt;exec dir="." executable="cmd"&gt;
              &lt;arg line="/c setEnv.bat" /&gt;
          &lt;/exec&gt;
   &lt;/target&gt;</code></p>
  
  <p>where setEnv.bat sets the enviroment variables to use msbuild</p>
  
  <p><code>@echo off
  REM Load Visual Studio's build tools
  call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x64</code></p>
  
  <p>and after it executes this</p>
  
  <p><code>&lt;target name="msbuildSln" depends="setEnv"&gt;
          &lt;exec executable="msbuild"&gt;
              &lt;arg value="${myproj.sln}" /&gt;
              &lt;arg value="/p:Configuration=Release" /&gt;
              &lt;arg value="/p:Platform=x64" /&gt;
          &lt;/exec&gt;
  &lt;/target&gt;</code></p>
  
  <p>The problem is that when i call the msbuild from the target msbuildSln the enviroment variable are not set in fact i have this message :</p>
  
  <p><code>BUILD FAILED
  C:\Users\workspace\MyProj\mybuild.xml:82: Execute failed: java.io.IOException: Cannot run program "msbuild": CreateProcess error=2, The system cannot find the file specified</code></p>
  
  <p>I think it is a problem of the cmd scope because if i launch it inside setEnv.bat it runs.
  I've tryed different solutions :<br/>
  1)Call directly msbuild from its folder and run my target <br/>
  2)Set the env. variable of vcvarsall.bat globally<br/>
  3)Doing a double call to my Ant script modifying mt setEnv.bat :<br/>
  <code>call "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x64 %*
  ant -f mybuild.xml msbuildSln</code> 
  setting like project default="setEnv" and removing the dependece from setEnv in the msbuildSln target.</p>
  
  <p>I'm adopting the last solution but i don't know if it affects the performance. But the most important point is there a way to set and use the vcvarsall.bat and msbuild together because i have to do many steps (like checkout from svn, built solution etc..)and i want to do it with Ant not putting all in a .bat file.
  Thanks.</p>