在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

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

调试器设置为


当前回答

I experienced the error-messages when attempting to build the primary WinForms (XAF) project. I could only execute the application one time then needed to shutdown the VS2015 IDE and restart before a rebuild could be performed. After some digging in the project's property pages - in the "debug" property page, a check box was selected - Enable the Visual Studio Hosting Process. I unchecked and restarted the IDE, the application is now building without - "unable to copy the {project}.exe" messages.

Visual Studio托管过程的目的是什么?

其他回答

使用Ms进程资源管理器查看是否需要在Windows 7中打开“应用程序体验”

在我的情况下,所有其他建议都不起作用(Windows 7, VS2019)

编译后,生成的. exe文件被重新锁定约一分钟。另一个奇怪的观察:当删除。exe文件时,它像往常一样消失在文件资源管理器中,但在刷新时(F5)重新出现。

您可以使用MS进程资源管理器来查找是否有任何进程持有生成的. exe文件的句柄。为此,查看进程资源管理器的“下窗格”,选择查看句柄而不是dll,并使用“查找”来搜索您的. exe文件。

这告诉我,这是Windows 7的“系统”进程,得到了一个句柄。exe。

一些研究显示,我必须打开Windows的“应用程序体验”服务(“自动启动”)才能永久摆脱这种奇怪的行为。


以下是更多信息: 在什么情况下,系统进程(PID 4)保留一个打开的文件句柄?

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

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

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

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

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

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

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

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

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

像这样:

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

有用的图像

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

修复2

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

我也遇到过同样的问题,我尝试了这里提到的很多不同的方法,但没有一个对我有效,唯一对我有效的解决方案是:

从解决方案的DEBUG文件夹中删除READ ONLY属性 将此添加到构建事件:如果存在“$(TargetPath)”。$(TargetPath).locked" $(TargetPath)。锁定" if exists "$(TargetPath)" move "$(TargetPath)"“$(定位路径).locked”

对我来说,它是Avast反病毒,不让visual studio写入/读取/执行文件。所以我不得不将Visual studio 2010/2012文件夹添加到防病毒排除列表中。就在那之后……它的工作原理。