在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
(有时)有用,但这让我很紧张。有办法阻止这一切发生吗?
调试器设置为
第一个消息错误解决方案:
在我的例子中,问题在于路径长度。
解决方案是减少/更改问题文件路径。如果问题出在项目中的文件上,你应该减少/更改存储库路径。
C:\Users\userTest\folder1\folder2\folder3\...\folderX\myProject\...\file.exe
如。
C:\Users\userTest\folder1\myProject\...\file.exe
换句话说,默认情况下路径长度不能超过260个字符。
原线程答案
(https://stackoverflow.com/a/73686473/12678101)
在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并进行一个新的构建将摆脱这两个问题,并像往常一样继续这个过程。