在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

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

调试器设置为


当前回答

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

其他回答

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.

我没有意识到我仍然连接着调试器,并试图在同一个Visual Studio实例中构建。一旦我停止调试器,我就能够构建。

我发疯了,试图找到为什么系统进程在我正在工作的EXE上保持一个打开的句柄,在它被终止后的另一分钟,我得到了与OP相同的错误。

原因是之前的开发人员在使用(){}时没有包装IDisposable对象。一旦IDisposable对象正确地销毁自己,错误不再发生,我能够立即重建。

在我的例子中,我在发布到它无法访问的文件夹时遇到了麻烦。您可以通过尝试发布到您的c驱动器中的一个文件夹来排除这种情况,您应该不会有访问问题。

我以管理员的身份运行Visual Studio,设法解决了这个问题。