title: MSBuild: parallel builds and .Net projects
body: <p>I've written a MSBuild project files which try to build in parallel all the configs of my VS2010 solution:</p>
  
  <pre><code>&lt;Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0"&gt;
    &lt;ItemGroup&gt;
      &lt;BuildFile Include="$(SourceRoot)MyProject.sln" /&gt;
      &lt;Config Include="Debug"&gt;
        &lt;Configuration&gt;Debug&lt;/Configuration&gt;
      &lt;/Config&gt;
      &lt;Config Include="Release"&gt;
        &lt;Configuration&gt;Release&lt;/Configuration&gt;
      &lt;/Config&gt;
    &lt;/ItemGroup&gt;
  
    &lt;Target Name="BuildAll" Outputs="%(Config.Configuration)"&gt;
      &lt;Message Text="Start building for configuration: %(Config.Configuration)" /&gt;
      &lt;MSBuild Projects="@(BuildFile)"
               Properties="Configuration=%(Config.Configuration)"
               Targets="Build" /&gt;
    &lt;/Target&gt;  
  &lt;/Project&gt; 
  </code></pre>
  
  <p>And I launch msbuild with:</p>
  
  <pre><code>msbuild /m /p:BuildInParallel=true /t:BuildAll buildall.proj 
  </code></pre>
  
  <p>The problem is that my solution have many .Net projects which all have the same output folder. These projects use also the same external assemblies.</p>
  
  <p>So very often, two output executables are generated at the same time and their dependencies copied at the same time. This leads to errors like:</p>
  
  <pre><code>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3001,9): 
  error MSB3021: 
  Unable to copy file "xxx\NLog.dll" to "D:\src\Blackbird\shared\bin\debug\NLog.xml". The process 
  cannot access the file 'xxx\NLog.dll because it is being used by another process. 
  </code></pre>
  
  <p>which I think means: "2 different projects use NLog and try to copy its assembly in the output folder at the same time"...</p>
  
  <p>Is there a way to get around that? I really would like to avoid to modify all the projects in the solution.</p>
  
  <p>Looking at the task source code "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(3001,9)", I've seen that it is possible to make msbuild retry the copy:</p>
  
  <pre><code>&lt;Copy
      SourceFiles="@(ReferenceCopyLocalPaths)"
      DestinationFiles="@(ReferenceCopyLocalPaths-&gt;'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"
      SkipUnchangedFiles="$(SkipCopyUnchangedFiles)"
      OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
      Retries="$(CopyRetryCount)"
      RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
      UseHardlinksIfPossible="$(CreateHardLinksForCopyLocalIfPossible)"
      Condition="'$(UseCommonOutputDirectory)' != 'true'"
      &gt; 
  </code></pre>
  
  <p>I've try to set the variables CopyRetryCount, CopyRetryDelayMilliseconds, ... I was hoping that if the copy fails, another copy done a few milliseconds later would succeed. But I've been unable to set these parameters. How can I change them?</p>
  
  <p>Is there another solution?</p>