title: TFS 2012 Build "Access to Path Denied"
body: <p>I’m using TFS 2012 Build and running into an error</p>
  
  <blockquote>
    <p>Access to the path is denied</p>
  </blockquote>
  
  <p>The solution being built contains about 15 projects of which a number are using the Castle.Components.Validator.2.5.0 assembly.<p>  I have seen other posts that talk about the TFS Build Access Denied errors, but they generally refer to having simultaneous builds running.  In this case only one build runs at a time.  Also, the error occurs when the server is restarted or the build has not run for some time.<p>Once a build is run and fails, the next one succeeds and each one after that succeeds again until the build hasn’t been run for a while or the server is restarted.  Although we can get around this, it is a manual headache.<p>  Here is the error:</p>
  
  <blockquote>
    <p>C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\Microsoft.Common.targets (3513): Unable to copy file "D:\Builds\12\Foo\Check-In Build\Sources\packages\Castle.Components.Validator.2.5.0\lib\NET40\Castle.Components.Validator.dll" to "D:\Builds\12\Foo\Check-In Build\Binaries\Castle.Components.Validator.dll".<p> Access to the path 'D:\Builds\12\Foo\Check-In Build\Binaries\Castle.Components.Validator.dll' is denied.</p>
  </blockquote>
  
  <p>When looking at the log file you can see that the build is trying to copy the file twice.  Because the first one has a lock on the file, the second one fails and thus the build fails.  Here is a snippet of the log file that shows what is happening:</p>
  
  <blockquote>
    <p>2>_CopyFilesMarkedCopyLocal:
             Copying file from "D:\Builds\12\Foo\Check-In Build\Sources\packages\Castle.Components.Validator.2.5.0\lib\NET40\Castle.Components.Validator.dll" to "D:\Builds\12\Foo\Check-In Build\Binaries\Castle.Components.Validator.dll".
        <p> 5>_CopyFilesMarkedCopyLocal:
             Copying file from "D:\Builds\12\Foo\Check-In Build\Sources\packages\Castle.Components.Validator.2.5.0\lib\NET40\Castle.Components.Validator.dll" to "D:\Builds\12\Foo\Check-In Build\Binaries\Castle.Components.Validator.dll".
       <p>  2>_CopyFilesMarkedCopyLocal:
             Copying file from "D:\Builds\12\Foo\Check-In Build\Sources\packages\MvcContrib.Mvc3.FluentHtml-ci.3.0.96.0\lib\MvcContrib.FluentHtml.dll" to "D:\Builds\12\Foo\Check-In Build\Binaries\MvcContrib.FluentHtml.dll".
             Copying file from "D:\Builds\12\Foo\Check-In Build\Sources\packages\RhinoMocks.3.6\lib\Rhino.Mocks.dll" to "D:\Builds\12\Foo\Check-In Build\Binaries\Rhino.Mocks.dll".</p>
  </blockquote>
  
  <p>Any help on how to fix this would be greatly appreciated.</p>