title: MSBuild fails with missing references sometimes
body: <p>I have created a build in TFS 2013, using VS 2013. My solution builds correctly in Visual Studio, and I can open the solution from the drop folder on the build server and compile it as well.</p>
  
  <p>The problem is that a triggered build will fail randomly, maybe around 60% of the time, with missing reference errors. The missing references are only my own projects that are built with the solution, not packages or Microsoft dlls. The number of actual missing reference errors varies as well, leading me to believe that the problem is related to file access handles. The build fails with the standard "MSBuild error 1". Here is an example error:</p>
  
  <pre><code>Helpers\SiteHelpers.cs (11): The type or namespace name 'ShoppingCart' does not exist in the namespace 'xxxxx.xxxxxxxxx.xxxxxxx' (are you missing an assembly reference?)
  </code></pre>
  
  <p>As I said, the project builds fine in Visual Studio, but I checked dependencies on the solution anyway, and everything appears to be correct.</p>
  
  <p>It may be worth noting that I am using TFS's Git implementation, so my build process file is currently GitTemplate.12.xaml. This file works fine for several other similar solutions I am working on.</p>
  
  <p>Edit:
  I opened the more detailed build logs and here is the section that happened to fail in this instance:</p>
  
  <pre>
  53>GenerateTargetFrameworkMonikerAttribute:
         Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
         CoreCompile:
           C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt /define:TRACE /highentropyva- /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\BusinessObject.dll" /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\Configuration.dll" /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\DataProvider.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll" /reference:"C:\Builds\5\xxxxGit\xxxx xxxx\bin\Utilities.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\ScheduledTransmissionProcessor.exe /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "C:\Users\xxxxxuser\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
      53>Program.cs(6,11): error CS0234: The type or namespace name 'BusinessLogic' does not exist in the namespace 'xxx' (are you missing an assembly reference?) [C:\Builds\5\xxxxGit\xxxx xxxx\src\Application\Console\ScheduledTransmissionProcessor\ScheduledTransmissionProcessor.csproj]
  </pre>
  
  <p>Here is the same section when the build succeeds:</p>
  
  <pre>
  52>GenerateTargetFrameworkMonikerAttribute:
  Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
         CoreCompile:
           C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /platform:AnyCPU /errorreport:prompt /define:TRACE /highentropyva- /reference:"C:\Builds\5\XXXXGit\XXXX XXXX\bin\BusinessLogic.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\BusinessObject.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\Configuration.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\DataProvider.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Xml.Linq.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\Utilities.dll" /reference:"C:\Builds\5\XXXXGit\xxxx xxxx\bin\UtilityServices.dll" /debug:pdbonly /filealign:512 /optimize+ /out:obj\Release\ScheduledTransmissionProcessor.exe /target:exe /utf8output Program.cs Properties\AssemblyInfo.cs "C:\Users\xxxxxuser\AppData\Local\Temp\.NETFramework,Version=v4.0.AssemblyAttributes.cs"
      53>CoreResGen:
  </pre>
  
  <p>It appears that the namespace can't be found because the reference is not included in the command line arguments for csc.exe.</p>
  
  <p>What would cause a build command to be randomly malformed? Could it be resources on the build machine? Something in the build process template?</p>
  
  <p>Edit 2:
  Here is an example of a project reference in the .csproj file of the project that caused the build failure in my posted error log:</p>
  
  <pre><code>&lt;ProjectReference Include="..\..\..\BusinessLogic\BusinessLogic.csproj"&gt;
        &lt;Project&gt;{0C3A2268-388A-4C88-8D4C-982FB00E573D}&lt;/Project&gt;
        &lt;Name&gt;BusinessLogic&lt;/Name&gt;
  &lt;/ProjectReference&gt;
  </code></pre>
  
  <p>This path is the same on my machine and the build machine since both versions are cloned from the same Git repository.</p>