在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

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

调试器设置为


当前回答

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

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

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

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

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

希望这对你有所帮助……

其他回答

对我来说,这是一个许可问题。我必须以管理员的身份运行Visual Studio。

这是因为你已经关闭了你的应用程序,但它仍然在后台运行。

临时解决方案:

进入任务管理器(Ctrl + Shift + Esc)。 进入进程选项卡,找到“YourProjectName.exe”。 如果找不到自己的进程,请勾选“显示来自所有用户的进程”。 结束处理

永久解决方案:必须通过编码关闭应用程序。这是代码…

System.Windows.Forms.Application.Exit();

您必须以所有形式将此代码放入表单的关闭事件中。例子:

private void frm_menu_FormClosing(object sender, FormClosingEventArgs e)
{
    System.Windows.Forms.Application.Exit();
}

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.

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

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

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

我在VS 2015中遇到了这个问题。我的环境的原因是使用StyleCop项目设置StyleCopAdditionalAddinPaths Include="…"来指定额外的StyleCop Addin路径。我使用的变通方法是从.csproj文件中删除这个项目设置,取而代之的是手动复制StyleCop AddIn中的StyleCop. csharp . rules .dll。不是一个优雅的解决方案,但我发现解决方案从来没有锁定dll之后,这样做。