在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

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

调试器设置为


当前回答

这发生在我使用IL支持插件时。

当您的项目中没有任何IL文件时(例如,因为您删除了最后一个文件),构建将失败,如问题中所述。

删除对IL的支持解决了这个问题

其他回答

引用:

一个解决方法是把它放在>项目的预构建事件命令行属性中(在构建事件选项卡中):

代码片段

if exist "$(TargetPath).locked" del "$(TargetPath).locked"

if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

.vhost.exe是一个调试器进程,因此正在调试的进程似乎没有正确关闭。有可能你有一个错误,使它仍然存在,并且没有正确地停止调试进程——当你单击“停止调试”而不是实际杀死调试器时,有一些选项可以从进程中分离出来,所以也许你有这样的设置。

但这就是问题所在——你试图复制的文件被操作系统锁定(即仍在使用),所以它阻止了复制。确保该文件是免费的,您将能够复制。

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

似乎通过更改项目的程序集名称就可以解决这个问题。

所以不是这样

我把它变成这个

注意,我只是把它从Increment and Recall改成了Increment_Recall,我只是去掉了空格。它现在对我来说工作得很好。

我能够修复这个问题(VS 2010)通过提供以下预构建操作;

if exist "$(TargetPath).locked" del "$(TargetPath).locked"

if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"