在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

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

调试器设置为


当前回答

必须在关闭后终止进程。 我用;

Process.GetCurrentProcess().Kill();

将此代码添加到您用于关闭的关闭事件或方法。

其他回答

另一个拼凑,额,但它很容易,为我在VS 2013工作。单击项目。在属性面板中应该有一个名为Project File的条目,该条目带有一个值

(你的项目名).vbproj

更改项目名称—例如在末尾添加-01。被锁定的原始.zip文件仍然在那里,但不再被引用…这样你的工作才能继续。下次计算机重新启动时,锁将消失,您可以删除错误文件。

我在Visual Studio 2013中遇到过类似的错误消息。

大多数情况下,我发现这种情况发生在调试进程因为异常而停止时。

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

关闭Visual Studio 删除bin和obj文件夹 重新开放Visual Studio。

此“bug”自Visual Studio 2003以来一直存在。

最后,我还发现我通常可以通过简单地重命名可执行文件然后删除它来克服这个问题。

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

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

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

在我的例子中,VS不能复制的文件是. task项目的文件,所以问题是我有一些本地运行的计划任务。一旦我停止并禁用它们,复制问题就消失了。

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.