在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

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

调试器设置为


当前回答

我发疯了,试图找到为什么系统进程在我正在工作的EXE上保持一个打开的句柄,在它被终止后的另一分钟,我得到了与OP相同的错误。

原因是之前的开发人员在使用(){}时没有包装IDisposable对象。一旦IDisposable对象正确地销毁自己,错误不再发生,我能够立即重建。

其他回答

我想我解决了这个问题,当一个进程在调试选项中中断时,我删除了中断所有进程的复选标记(op的第一个截图->第二个选项)。 自从我未检查它以来,它已经运行了一段时间。 我在我的项目中使用MySql NET连接器和DevExpress控件。可能其中一个没有很好地处理连接、绑定等,因为这个标志被激活了。

编辑:绝对有效!没有更多的“无法复制文件”,没有更多的表单设计器错误。

在我的例子中,我在发布到它无法访问的文件夹时遇到了麻烦。您可以通过尝试发布到您的c驱动器中的一个文件夹来排除这种情况,您应该不会有访问问题。

我能够修复这个问题(VS 2010)通过提供以下预构建操作;

if exist "$(TargetPath).locked" del "$(TargetPath).locked"

if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

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)保留一个打开的文件句柄?