在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

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

调试器设置为


当前回答

如果我使用VS2012在WP8上编辑Xaml页面,每次部署都会遇到这个问题。

我需要要么不打开Xaml页面,要么使用进程资源管理器杀死进程XDesProc.exe。

如果您得到这个错误,那么我建议使用进程资源管理器来查看发生了什么(即使这是一个不同的问题)。只要找到进程“WeinGartner.WeinCad.exe”,它应该显示进程和处理访问文件(好吧,至少当杀死vhost文件不解决问题)。

其他回答

问题是调试器/构建器创建的可执行文件或库被反病毒程序识别为威胁,因此在可以执行之前立即删除。

最好你应该调整你的反病毒软件,不分析你的项目文件夹。


按照从好到坏的顺序,有以下几种方法:

将项目文件夹从防病毒程序中排除 不包括pdb文件(不是100%保证修复) 关闭实时保护(不推荐)

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.

看看另一个答案。基本上,你可以让MSBuild.exe进程在后台运行,消耗资源文件。如果你有任何构建前或构建后的任务,导致MSBuild通过命令行启动,尝试添加"/nr:false"标志到这个命令。但是,关于更具体的细节,请参见前面的回答。

我终于怎么修了。为什么我们不能在第一次调试后继续调试,因为第一次调试exe仍在运行。这样,在第一次调试之后,您需要进入任务管理器->进程选项卡->[您的项目名称exe]结束exe进程。

这对我很有用:)

在Visual Studio Premium 2013 (Update 3)中,我用一个预构建的一行程序解决了这个问题:

(if exist "$(TargetDir)*old.pdb" del "$(TargetDir)*old.pdb") & (if exist "$(TargetDir)*.pdb" ren "$(TargetDir)*.pdb" *.old.pdb)

这将优雅地删除任何旧的PDB文件(如果可以的话),然后重命名任何带有.old的文件。pdb的扩展。一个很好的副作用是,如果旧的PDB仍然是锁定的,它只是在文件名中添加另一个.old块,并且在下次重新启动Visual Studio并进行构建时,它们都将被清除。

例如,构建/调试会话1离开MyProject。pdb锁定。 下次构建时: MyProject的。MyProject.old.pdb

然后,构建/调试会话2启动,并且MyProject。pdb和MyProject.old.pdb仍然锁定: MyProject.old.pdb—> MyProject.old.old.pdb MyProject的。MyProject.old.pdb

最后,重新启动Visual Studio并进行一个新的构建将摆脱这两个问题,并像往常一样继续这个过程。