在VS2012 c#项目的构建过程中,我一直得到这个错误

Error   41  Could not copy "obj\Debug\WeinGartner.WeinCad.exe" to
 "bin\Debug\WeinGartner.WeinCad.exe". 
 Exceeded retry count of 10. Failed.    


Error   42  Unable to copy file "obj\Debug\WeinGartner.WeinCad.exe" to
"bin\Debug\WeinGartner.WeinCad.exe". The process cannot access the file
'bin\Debug\WeinGartner.WeinCad.exe' because it is being used by another 
process.    

现在我知道该终止进程了

Weingartner.WeinCad.vhost.exe

(有时)有用,但这让我很紧张。有办法阻止这一切发生吗?

调试器设置为


当前回答

I ran into this as well. It turns out that I had been testing with a service which I had built myself and which was running out the of the ..\bin\release directory of one of the projects in my solution. I had got the service running, but I forget to stop/uninstall it before returning to testing. As a result, it was holding on to one of the dlls that I reference and which needed to be moved (automatically as a dependency) from one project's bin/release subfolders to another. Stopping the service solved the problem.

其他回答

花了几个小时试图解决这个问题,然后发现我正在处理一个服务-记住停止任何服务作为解决方案的一部分!

Use

Debug.Flush();
Debug.Close();

如果发生异常,则在catch或finally中阻塞。

编辑: 我个人遇到过这个问题,我通常会做一个小技巧,效果很好。 我将构建类型从“调试”更改为“发布”(如果已经存在,则将“发布”更改为“调试”)。

请确保关闭所有wcfSvcHost实例,然后重试。 这对我很管用!

如果您正在调试T4模板,那么这种情况经常发生。我的解决方案(在MS修复这个问题之前)将只是杀死这个进程:

任务管理器—> User—> T4VSHostProcess.exe

此过程仅在调试T4模板时出现,而不会在运行T4模板时出现。

如果没有一个答案是正确的,试试这个简单的检查。 找到任何MSbuild.exe运行和持有您的项目EXE。杀死MSBuild.exe,你应该很好。