C# Visual Studio“无法复制”......在构建过程中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18102859/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio "Could not copy" .... during build
提问by bradgonesurfing
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
我的调试器设置是
采纳答案by Gerard
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
- Deleting the
bin
andobj
folders, and - Reopening Visual Studio.
- 关闭 Visual Studio
- 删除
bin
和obj
文件夹,以及 - 重新打开 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.
最后,我还发现我经常可以通过简单地重命名可执行文件然后删除它来解决这个问题。
回答by Allan Zeidler
Sometimes it cannot clear the DEBUG folder. What I did and worked was renaming the file that could not be deleted. So, erase all the folder and the file that cannot be deleted, rename to, for example, "_old".
有时它无法清除 DEBUG 文件夹。我所做和所做的是重命名无法删除的文件。因此,将所有无法删除的文件夹和文件擦除,重命名为例如“_old”。
回答by drlff
I realize this is just adding to the already huge amount of answers for this question, but thought it deserved mentioning that, although not perfect, a combination of the answers given by: @Stefano, @MichaelRibbons, and @IvanFerrerVilla has provided a decent bit of success, when neither of them on their own was very successful.
我意识到这只是增加了这个问题的大量答案,但我认为值得一提的是,虽然并不完美,但@Stefano、@MichaelRibbons 和 @IvanFerrerVilla 给出的答案组合提供了不错的答案成功的时候,当他们两个人都不是很成功时。
回答by live-love
Using DNN. I solved the problem by editing the MSBuild.Community.Tasks.Targets file and changing the bin path:
使用 DNN。我通过编辑 MSBuild.Community.Tasks.Targets 文件并更改 bin 路径解决了这个问题:
<MSBuildDnnBinPath Condition="'$(MSBuildDnnBinPath)' == ''">$(MSBuildProjectDirectory)\bin</MSBuildDnnBinPath>
回答by Pompair
If you are debugging T4 templates, then this happens all the time. My solution (before MS fixes this) would be just to kill this process:
如果您正在调试 T4 模板,那么这种情况一直会发生。我的解决方案(在 MS 修复此问题之前)只是终止此过程:
Task Manager --> User --> T4VSHostProcess.exe
任务管理器 --> 用户 --> T4VSHostProcess.exe
This process only comes up when you debug a T4 template, not when you run one.
此过程仅在您调试 T4 模板时出现,而不是在您运行时出现。
回答by Nair
I was able to fix this issue (VS 2010) through supplying following pre build action;
通过提供以下预构建操作,我能够解决此问题(VS 2010);
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
回答by Ivan Ferrer Villa
I think I solved it removing the check mark to Break all processes when one process breaks
in Debug options (op's first screenshot->second option).
It's been building/running well for a while since I unchecked it.
I'm using MySql NET Connector and DevExpress controls in my project. May be one of them was not disposing connections, bindings, etc. well because of this flag beeing activated.
我想我解决了它Break all processes when one process breaks
在调试选项中删除复选标记(操作的第一个屏幕截图->第二个选项)。
自从我取消选中它以来,它一直在构建/运行良好。
我在我的项目中使用 MySql NET 连接器和 DevExpress 控件。可能是因为这个标志被激活,其中之一没有很好地处理连接、绑定等。
EDITED: definitely it works! No more 'Unable to copy file' and no more Form designer errors.
编辑:绝对有效!不再有“无法复制文件”,也不再有表单设计器错误。
回答by Uriil
In my case it was Resharper Unit Tests runner(plus NUnit tests, never had such problem with MsTests). After killing the process, was able to rebuild process, without restarting OS or VS2013
就我而言,它是 Resharper 单元测试运行程序(加上 NUnit 测试,MsTests 从来没有出现过这样的问题)。杀死进程后,能够重建进程,无需重新启动操作系统或VS2013
回答by Ashwin J
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 Update 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...
希望这可以帮助...
回答by gbjbaanb
the .vhost.exe is a debugger process, so it appears that the process being debugged hasn't closed properly. 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.
.vhost.exe 是一个调试器进程,因此被调试的进程似乎没有正确关闭。很可能您有一个错误使其保持活动状态并且没有正确停止调试过程 - 当您单击“停止调试”而不是实际终止调试器时,有一些选项可以从过程中分离出来,所以也许您已经设置好了。
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.
但这就是问题所在 - 您尝试复制的文件已被操作系统锁定(即仍在使用),因此无法复制。确保该文件是免费的,您将能够复制。
回答by progLearner
I have add the same problem various times and none of the answers from this treat could help or if they did it was by using a nasty work around.
What I figured is that there is always a good reason for this problem to occur (And is not a Microsoft bug! - Well, VS could get better at flagging it though :-)).
我多次添加了相同的问题,但这种治疗中的任何答案都无济于事,或者如果他们这样做是通过使用令人讨厌的解决方法。
我认为这个问题总是有一个很好的理由发生(而且不是微软的错误! - 嗯,虽然 VS 可以更好地标记它:-))。
The main reason may simply be that your project dependencies are messed up!
As a simple example ():
主要原因可能只是你的项目依赖搞砸了!
举个简单的例子():
- You have multiple projects within a same solution
- You clean + build all and assume everything went well as you see no error
- You start running one of the project - All good so far!
- Then start running a second one, but this one has dependencies also used by the previous project and tries to rebuild them
- It then hangs for a while
- It fails to build as the first project is already running and does not allow you to override ongoing processes
- 您在同一个解决方案中有多个项目
- 你清理+构建所有并假设一切顺利,因为你看不到错误
- 您开始运行该项目之一 - 到目前为止一切顺利!
- 然后开始运行第二个,但这个依赖项也被前一个项目使用并尝试重建它们
- 然后挂了一段时间
- 它无法构建,因为第一个项目已经在运行,并且不允许您覆盖正在进行的进程
Now you can think of all the possible scenarios that could trigger an error of the sort:
现在您可以想到可能触发此类错误的所有可能场景:
Error Could not copy "obj\Debug\ProjectX.exe" to "..\bin\Debug\ProjectX.exe". Exceeded retry count of 10. Failed. The file is locked by: "ProjectX (17132)" ProjectX
Fixing this issue is usually a tedious process as you will have to perfectly understand all the dependencies in your system
解决此问题通常是一个乏味的过程,因为您必须完全了解系统中的所有依赖项