title: TFS Build - "The process cannot access the file because it is being used by another process"
body: <p>We have a legacy solution (>300 projects across several solutions) currently running in the old Xaml build definitions. I'm trying to convert it to the vNext build definitions, but I'm having intermittent errors.</p>
  
  <p>Every so often, a file in the process will become locked, and cause the build to throw the following error:</p>
  
  <blockquote>
    <p>CSC (0, 0) Metadata file 'E:\Builds\1\3\a\Newtonsoft.Json.dll' could not be opened -- The process cannot access the file 'xxx.dll' because it is being used by another process.</p>
  </blockquote>
  
  <p>Its a different file every time (this latest was Newtonsoft.json.dll - a nuget package), and not always the same solution. Subsequent builds will work fine.</p>
  
  <p>I've tried to resolve this by adding <code>/NodeReuse:false</code> to the build arguments, and whilst it appears to have reduced the frequency a little, it still hasn't resolved the issue.</p>
  
  <p>Due to the nature of the build, and the fact it relies on the projects outputting to a common location (projects use a combination of File and Project references), I have the following settings configured:</p>
  
  <p><code>/p:OutDir="$(build.stagingDirectory)" /p:ReferencePath="$(build.stagingDirectory)" /NodeReuse:False</code></p>
  
  <p>It's almost always the Staging Directory that these dlls are located within.</p>
  
  <p>Reconfiguring the product to exclusively use Project References is unfortunately not viable at this time.</p>
  
  <p>Is there something I can do to the build step to eliminate these locking issues?</p>