在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

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

调试器设置为


当前回答

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

这对我很管用。

其他回答

在我的情况下(Windows 10, Visual Studio 2015):

任务管理器->用户-> EndTask=>vshost.exe

(它会立即重新启动,你可以重新构建)

@Gerard的答案是正确的。

当clean+build不能为我解决这个问题时,我通过以下方法取得了成功:

Closing Visual Studio
Deleting the bin and obj folders, and
Reopening Visual Studio.

但我需要在主机上做一些额外的工作:

> Add-Migration Initial
> Update-Database

然后我开始调试,它起作用了。

在我的例子中,VS不能复制的文件是. task项目的文件,所以问题是我有一些本地运行的计划任务。一旦我停止并禁用它们,复制问题就消失了。

引用:

一个解决方法是把它放在>项目的预构建事件命令行属性中(在构建事件选项卡中):

代码片段

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

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

.vhost.exe是一个调试器进程,因此正在调试的进程似乎没有正确关闭。有可能你有一个错误,使它仍然存在,并且没有正确地停止调试进程——当你单击“停止调试”而不是实际杀死调试器时,有一些选项可以从进程中分离出来,所以也许你有这样的设置。

但这就是问题所在——你试图复制的文件被操作系统锁定(即仍在使用),所以它阻止了复制。确保该文件是免费的,您将能够复制。