MSBuild";无法复制文件";在CI环境中

MSBuild";无法复制文件";在CI环境中,msbuild,hudson,Msbuild,Hudson,我使用Hudson作为持续集成服务器。这些作业最终启动了MSBuild。每个人偶尔,我的生成会失败,并在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

我使用Hudson作为持续集成服务器。这些作业最终启动了MSBuild。每个人偶尔,我的生成会失败,并在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.
当我检查“bin\Debug\Microsoft.Practices.Unity.Configuration.dll”时,我发现它是一个0字节的文件


我不明白为什么这个文件有问题。有什么想法吗?

听起来像是一个进程正在打开bin\Debug\Microsoft.Practices.Unity.Configuration.dll。
您可以先将“bin”重命名为其他名称,如“bin old”,然后删除“bin old”,如果任何进程保持“bin”中的文件处于打开状态,则重命名将失败。

使用SysInternals(Microsoft)中的Handle.exe查看哪些文件被哪些进程保持打开状态

当您收到错误时,在cmd提示符下运行此命令; Handle.exe>OpenFile.txt Notepad.exe OpenFile.txt

然后在OpenFile.txt中搜索被锁定的文件,您将看到该过程


Ryan

另请参见和

MS Build Copy任务具有未记录的功能,至少谷歌保持沉默。 如果设置了系统范围的环境变量MSBUILDALWAYSRETRY=1 此任务将重试复制文件,即使在复制操作期间出现访问被拒绝异常

输出示例

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.

从系统内部使用ProcessExplorer将是一种更直接的方法。选择“查找”。。“查找句柄或DLL…”,然后将文件名粘贴到搜索框中。我发现重新启动生成服务也有帮助。请在MSBuild git上验证:这很酷,但如何防止vs2012锁定该文件?它确实被devenv.exe进程劫持,在vs2012重新启动之前无法继续。不知道如何在这方面提供帮助。我的解决方案旨在帮助找到一种更快失败的机制,这样在等待几乎整个构建完成之后,您就不会发现失败。