在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

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

调试器设置为


当前回答

删除Bin文件夹中的Debug或Release文件夹下的所有.cache文件。

其他回答

此问题通常在运行测试时发生。如果这是你的情况,只需转到任务管理器并杀死testHost

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.

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

我在Windows 8上的VS 2012 Version 11.0.60610.01 Update 3上遇到了同样的问题

没有打开设计器窗口,项目是一个简单的控制台应用程序。

删除访问该文件的vshost进程在大多数情况下都不起作用,因为该进程没有访问该文件。

最简单的工作方法是将项目从解决方案中删除,在解决方案中构建另一个项目,然后将原始项目添加回来。

这是一种刺激和浪费时间,但这是我所知道的所有其他选择中最便宜的。

希望这对你有所帮助……

在你的主项目taskkill /f /fi "pid gt 0" /im "YourProcess.vshost.exe"中添加预构建事件