在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

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

调试器设置为


当前回答

在你的主项目taskkill /f /fi "pid gt 0" /im "YourProcess.vshost.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.

@Gerard的答案是正确的。

当clean+build不能为我解决这个问题时,我通过以下方法取得了成功:

Closing Visual Studio
Deleting the bin and obj folders, and
Reopening Visual Studio.

但我需要在主机上做一些额外的工作:

> Add-Migration Initial
> Update-Database

然后我开始调试,它起作用了。

如果我使用VS2012在WP8上编辑Xaml页面,每次部署都会遇到这个问题。

我需要要么不打开Xaml页面,要么使用进程资源管理器杀死进程XDesProc.exe。

如果您得到这个错误,那么我建议使用进程资源管理器来查看发生了什么(即使这是一个不同的问题)。只要找到进程“WeinGartner.WeinCad.exe”,它应该显示进程和处理访问文件(好吧,至少当杀死vhost文件不解决问题)。

进入“工具>>选项>>数据库工具>>常规” 检查脚本/查询执行情况

我已经添加了不同次相同的问题,从这个治疗没有一个答案可以帮助,或者如果他们这样做了,使用一个讨厌的工作。 我认为这个问题总是有一个很好的原因发生(不是微软的bug!)-好吧,不过VS在标记方面可以做得更好:-))。

主要原因可能只是你的项目依赖关系搞砸了! 作为一个简单的例子():

在同一个解决方案中有多个项目 你清理+构建所有,并假设一切都很顺利,因为你没有看到错误 您开始运行其中一个项目—到目前为止一切正常! 然后开始运行第二个项目,但这个项目也有前一个项目使用的依赖项,并尝试重新构建它们 然后挂一段时间 它无法在第一个项目已经运行时进行构建,并且不允许您覆盖正在进行的流程

现在,您可以想到所有可能触发此类错误的场景:

Error Could not copy "obj\Debug\ProjectX.exe" to "..\bin\Debug\ProjectX.exe". Exceeded retry count of 10. Failed. The file is locked by: "ProjectX (17132)" ProjectX

修复这个问题通常是一个乏味的过程,因为您必须完全理解系统中的所有依赖项