2

I'm using Hudson as a continuous integration server. The jobs ultimately kick off MSBuild. Everyone once in a while, my build fails with a non-code-compilation error out of MSBuild:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(2703,9): error MSB3021: Unable to copy file "..\Lib\Microsoft\Microsoft.Practices.Unity.Configuration.dll" to "bin\Debug\Microsoft.Practices.Unity.Configuration.dll". Access to the path 'bin\Debug\Microsoft.Practices.Unity.Configuration.dll' is denied.

When I examine 'bin\Debug\Microsoft.Practices.Unity.Configuration.dll', I find it to be a 0-byte file.

I'm at a loss for why this file is being problematic. Any ideas?

Trinition
  • 1,153
  • 2
  • 15
  • 25

4 Answers4

6

MS Build Copy task has undocumented feature, at least Google keeps silence. If set system wide environment variable MSBUILDALWAYSRETRY=1 This task will retry to copy a file even it gets Access Denied exception during copy operation

Example of output

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (3513): Got System.UnauthorizedAccessException: Access to the path 'C:\Builds\8\28\Binaries\Release\fr\System.Spatial.resources.dll' is denied.
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
   at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite, Boolean checkHost)
   at System.IO.File.Copy(String sourceFileName, String destFileName, Boolean overwrite)
   at Microsoft.Build.Tasks.Copy.CopyFileWithLogging(FileState sourceFileState, FileState destinationFileState)
   at Microsoft.Build.Tasks.Copy.DoCopyWithRetries(FileState sourceFileState, FileState destinationFileState, CopyFileWithState copyFile) copying C:\Builds\8\28\Sources\Main\Solutions\packages\System.Spatial.5.2.0\lib
et40\fr\System.Spatial.resources.dll to C:\Builds\8\28\Binaries\Release\fr\System.Spatial.resources.dll and HR is -2147024891
 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (3513): Retrying on ERROR_ACCESS_DENIED because MSBUILDALWAYSRETRY = 1
 C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets (3513): Could not copy "C:\Builds\8\28\Sources\Main\Solutions\packages\System.Spatial.5.2.0\lib
et40\fr\System.Spatial.resources.dll" to "C:\Builds\8\28\Binaries\Release\fr\System.Spatial.resources.dll". Beginning retry 1 in 1000ms. Access to the path 'C:\Builds\8\28\Binaries\Release\fr\System.Spatial.resources.dll' is denied.
diyoda_
  • 5,274
  • 8
  • 57
  • 89
Nick Kashtanov
  • 161
  • 2
  • 4
1

Sounds like a process is holding bin\Debug\Microsoft.Practices.Unity.Configuration.dll open. You can check that earlier by renaming 'bin' to something else, like 'bin-old' and then removing 'bin-old' If any process is holding the files in 'bin' open, the rename will fail.

Michael Donohue
  • 11,776
  • 5
  • 31
  • 44
  • this is cool and all, but how do we prevent vs2012 from locking the file? it is indeed being held hostage by devenv.exe process, and can no proceed until vs2012 restarts. – Kirka121 Jan 23 '14 at 16:21
  • 1
    Not sure how to help on that front. My solution is meant to help find a fail-faster mechanism, so you don't find out about the failure after waiting for nearly the whole build to complete. – Michael Donohue Jan 25 '14 at 02:53
0

Use Handle.exe from SysInternals (Microsoft) to see which files are being held open by which processes.

Run this at a cmd prompt when you get the error; Handle.exe > OpenFile.txt Notepad.exe OpenFile.txt

Then search OpenFile.txt for the file that is locked and you'll see the process.

Ryan

Ryan O'Neill
  • 5,410
  • 4
  • 46
  • 69
  • Using ProcessExplorer from SysInternals would be a more direct way of doing this. Select "Find" .. "Find Handle or DLL.." and then paste the file name into the search box. – Michael Donohue Jul 16 '09 at 16:50