在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.

其他回答

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

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

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

对我来说,它是Avast反病毒,不让visual studio写入/读取/执行文件。所以我不得不将Visual studio 2010/2012文件夹添加到防病毒排除列表中。就在那之后……它的工作原理。

问题是调试器/构建器创建的可执行文件或库被反病毒程序识别为威胁,因此在可以执行之前立即删除。

最好你应该调整你的反病毒软件,不分析你的项目文件夹。


按照从好到坏的顺序,有以下几种方法:

将项目文件夹从防病毒程序中排除 不包括pdb文件(不是100%保证修复) 关闭实时保护(不推荐)

我不能给出一个解决方案来防止这种情况发生,但你至少可以重命名锁定文件(windows资源管理器,或经典命令窗口),然后编译/构建。不需要重启VS201x。如果有一些经验,你可以添加一个预构建脚本来删除旧文件或重命名,以防出现锁。

我想我解决了这个问题,当一个进程在调试选项中中断时,我删除了中断所有进程的复选标记(op的第一个截图->第二个选项)。 自从我未检查它以来,它已经运行了一段时间。 我在我的项目中使用MySql NET连接器和DevExpress控件。可能其中一个没有很好地处理连接、绑定等,因为这个标志被激活了。

编辑:绝对有效!没有更多的“无法复制文件”,没有更多的表单设计器错误。