本文翻译自:Visual Studio “Could not copy” … during build
I keep getting this error during the build of my VS2012 C# project 在我的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.
Now I've figured out that killing the process 现在我想通了
Weingartner.WeinCad.vhost.exe
works (sometimes ) but this is getting on my nerves. 有效(有时),但这让我感到不安。 Any way to stop this happening at all? 有什么办法可以阻止这种情况的发生?
My debugger settings are 我的调试器设置是
#1楼
参考:https://stackoom.com/question/1DxNb/Visual-Studio-无法复制-在构建过程中
#2楼
the .vhost.exe is a debugger process, so it appears that the process being debugged hasn't closed properly. .vhost.exe是一个调试器进程,因此似乎正在调试的进程没有正确关闭。 Chances are you have a bug that's keeping it alive and are not stopping the debug process correctly - there are options to detach from the process when you click 'stop debugging' instead of actually killing the debugger so maybe you have that set. 您可能有一个使它保持活动状态并且没有正确停止调试过程的错误-单击“停止调试”而不是实际上杀死调试器时,有一些选项可以从该过程中分离出来,所以也许您有相应的设置。
But that's the problem - the file you're trying to copy over is locked (ie still being used) by the OS so its preventing the copy. 但这就是问题-您试图复制的文件已被操作系统锁定(即仍在使用),因此阻止了复制。 Ensure that file is free and you'll be able to copy. 确保该文件是免费的,并且您将能够复制。
#3楼
I faced the same problem on VS 2012 Version 11.0.60610.01 Update 3 on Windows 8 我在Windows 8上的VS 2012版本11.0.60610.01更新3上遇到了相同的问题
There were no designer windows open and the project was a simple console application. 没有打开设计器窗口,该项目是一个简单的控制台应用程序。
The removal of the vshost process accessing the file does not work most of the time since the process isn't accessing the file. 在大多数情况下,删除访问文件的vshost进程不起作用,因为该进程未访问文件。
The simplest workaround that works and takes the least amount of time is to remove the project from the solution, build another project in the solution and then add the original back. 可行且耗时最少的最简单的解决方法是从解决方案中删除项目,在解决方案中构建另一个项目,然后再添加原始项目。
It's an irritant and waste of time but it's the least expensive of all the other options that I know of. 这是一种刺激性和浪费时间,但它是我所知道的所有其他选项中最便宜的。
Hope this helps... 希望这可以帮助...
#4楼
I have encountered similar error messages in Visual Studio 2013. 我在Visual Studio 2013中遇到了类似的错误消息。
Mostly, I have found that this situation has occurred when a debug process was halted because of an exception. 通常,我发现,由于异常而停止调试过程时,会发生这种情况。
When clean+build has not resolved this problem for me, I have had success by doing the following: 当clean + build无法为我解决此问题时,请执行以下操作以取得成功:
- Closing Visual Studio 关闭Visual Studio
- Deleting the
bin
andobj
folders, and 删除bin
和obj
文件夹,以及 - Reopening Visual Studio. 重新打开Visual Studio。
This "bug" has existed since Visual Studio 2003. 自Visual Studio 2003以来,此“错误”一直存在。
Finally, I have also found that I can often overcome this problem by simply renaming the executable file and then deleting it. 最后,我还发现我通常可以通过简单地重命名可执行文件然后删除它来解决此问题。
#5楼
我已经通过杀死任务管理器中的IISExpress解决了它
#6楼
I cannot give a solution to prevent this from happening but you can at least RENAME the locked file (windows explorer, or classic command window) and then compile/build. 我无法提供解决方案来防止这种情况的发生,但是您至少可以重命名锁定的文件(Windows资源管理器或经典命令窗口),然后进行编译/构建。 No need to reboot or restart VS201x. 无需重新启动或重新启动VS201x。 With some experience you can add a pre-build script to delete old files or rename then out-of-the-way in case there's a lock. 有了一些经验,您可以添加一个预构建脚本来删除旧文件或重命名,然后在存在锁定的情况下进行重命名。