在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

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

调试器设置为


当前回答

@Gerard的答案是正确的。

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

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

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

> Add-Migration Initial
> Update-Database

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

其他回答

@Geoff (https://stackoverflow.com/a/25251766/3739540)的回答很好,但在重新编译时抛出错误代码1。

下面是对我有用的(2>nul 1>nul在结束+退出0):

(if exist "$(TargetDir)*old.pdb" del "$(TargetDir)*old.pdb") & (if exist "$(TargetDir)*.pdb" ren "$(TargetDir)*.pdb" *.old.pdb) 2>nul 1>nul
(if exist "$(TargetDir)*old.dll" del "$(TargetDir)*old.dll") & (if exist "$(TargetDir)*.dll" ren "$(TargetDir)*.dll" *.old.dll) 2>nul 1>nul
exit 0

我找到了一个完整的解决方案!

大多数答案告诉你杀死进程,然而与进程黑客,我找不到任何。

我找到了一个相对简单的解决方案。

在窗体设计器中选择您的主窗体。 单击属性菜单上的事件选项卡。 双击事件FormClosing。这将自动生成事件系统和函数:

private void[你的表单名]_FormClosing(对象发送器,FormClosingEventArgs e)

在这个函数中,添加Application。退出

像这样:

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
    Application.Exit();
}

有用的图像

我希望这能有所帮助!这道题真糟糕!

修复2

打开一项名为“应用体验”的服务。

花了几个小时试图解决这个问题,然后发现我正在处理一个服务-记住停止任何服务作为解决方案的一部分!

遵循以下步骤

打开任务管理器(Ctrl + Alt + Delete) 在Performance选项卡下选择<ProjectNameOfYours.exe>。 单击End Process。 现在构建解决方案。

以上步骤永久地解决了错误。

如果没有一个答案是正确的,试试这个简单的检查。 找到任何MSbuild.exe运行和持有您的项目EXE。杀死MSBuild.exe,你应该很好。