title: SpecsFor MVC / MSBuild.exe not building / publishing project correctly in Visual Studio 2012
body: <p>I am trying to use <a href="http://specsfor.com/SpecsForMvc/" rel="nofollow noreferrer">SpecsFor MVC</a> for automated acceptance testing and I have noticed that it is not building / publishing project correctly on Visual Studio 2012 and hence IIS Express is not running, ending in a 'Page cannot be displayed' message throughout the automated acceptance test.  </p>
  
  <p>To take you through all my tests to get this working, initially, when trying to run the automated tests, I was getting a 'Build Failed' message when running </p>
  
  <pre><code>_host = new SpecsForIntegrationHost(config);
  _host.Start();
  </code></pre>
  
  <p>.  After loading the SpecsFor MVC source code, I have noticed that the error was because the <code>MSBuild.exe</code> process was failing and the output message was being written to <code>Console.Output</code>.  After checking the output, I have noticed that the error was that the <code>Microsoft.WebApplication.targets</code> was not found.  After some research, I found the below:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/19718281/external-vs2013-build-error-error-msb4019-the-imported-project-path-was-not">External VS2013 build error &quot;error MSB4019: The imported project &lt;path&gt; was not found&quot;</a>
  
  <ul>
  <li>The one with most votes spoke about removing the <code>&lt;PropertyGroup&gt;</code> node from the <code>.csproj</code> which after removing it, the <code>MSBuild.exe</code> was not exiting with an error code as it only had warnings which still resulted in the project not being built &amp; published correctly.  SpecsFor MVC in this case treated this scenario as successful and proceeded with launching IIS Express but since the project was not built successfully, the acceptance tests resulted in another <code>Page Cannot Be Displayed</code> message as IIS Express was not running correctly.</li>
  </ul></li>
  <li>After some further research, I found <a href="https://stackoverflow.com/questions/17433904/v11-0-webapplications-microsoft-webapplication-targets-was-not-found-when-file-a">v11.0\WebApplications\Microsoft.WebApplication.targets was not found when file actually references v10</a> which outlined that VS 2012 has a new different MSBuild.exe file located in <code>C:\Program Files (x86)\MSBuild\12.0\Bin</code>.  
  
  <ul>
  <li>Now the issue is that within the SpecsFor MVC <code>IISTestRunnerAction.PublishSite()</code> method, the path of the <code>MSBuild.exe</code> is being loaded through
  <code>System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()</code> which in my case is outputting <code>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\</code>.  Changing this manually to <code>C:\Program Files (x86)\MSBuild\12.0\Bin</code> solved the issue and project was built  &amp; published successfully.</li>
  </ul></li>
  </ul>
  
  <p>My final question is: Is there a way where one can change the value of <code>System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()</code> so that I wouldn't need to update the source of the SpecsFor MVC project?</p>
  
  <p>Thanks in advance for any help!</p>