在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

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

调试器设置为


当前回答

在你的主项目taskkill /f /fi "pid gt 0" /im "YourProcess.vshost.exe"中添加预构建事件

其他回答

@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

重置IIS,停止使用您的DLL的服务(可能是控制台应用程序或windows服务托管应用程序或IIS),然后尝试。

这对我很管用。

此问题通常在运行测试时发生。如果这是你的情况,只需转到任务管理器并杀死testHost

异常

在某些情况下,在Visual Studio当你(Build || Rebuild)在上面 运行IISExpress时,你会遇到这个异常:

无法复制文件"obj\Debug\YourProjectName.dll"到bin\YourProjectName.dll"。进程无法访问该文件 'bin\YourProjectName.dll',因为它正在被其他人使用 过程

解决方案

右键单击需要构建的web项目。 单击属性。 在左侧选择Build Events选项卡。 在Pre-build events命令行中粘贴这两行:

tasklist /fi “imagename eq iisexpress.exe” |find “:” > NUL 如果错误级别 1 任务杀死 /f /im “iisexpress.exe”

你很好!

打开项目属性[菜单>项目>属性] 选择“调试”选项卡 取消勾选“启用visual studio托管进程” 启动调试[F5] 你会收到安全警告,只是“ok”。让应用程序运行 停止调试。 检查选项“启用visual studio托管进程”,在调试选项卡下, 现在,尝试开始调试,您将不会再次看到错误

[为我工作]