visual-studio 无法将文件 reference.dll 复制到 bin/reference.dll。该进程无法访问文件 reference.dll,因为它正被另一个进程使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1121386/
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
Unable to copy file reference.dll to bin/reference.dll. The process cannot access the file reference.dll because it is being used by another process
提问by Justin
For one of my ASP.NET 3.5 applications, every single time I try to build the web app, it throws the following build errors in Visual Studio 2008:
对于我的 ASP.NET 3.5 应用程序之一,每次我尝试构建 Web 应用程序时,它都会在 Visual Studio 2008 中引发以下构建错误:
Error 165 Unable to copy file "C:\InOne\Common\DexProcessor\bin\Debug\DexProcessor.dll" to "bin\DexProcessor.dll". The process cannot access the file 'bin\DexProcessor.dll' because it is being used by another process. InVision2 Error 166 Unable to copy file "C:\InOne\Common\DexParser\bin\Debug\InOne.DexParser.dll" to "bin\InOne.DexParser.dll". The process cannot access the file 'bin\InOne.DexParser.dll' because it is being used by another process. InVision2 Error 167 Unable to copy file "C:\InOne\Common\AlertProcessor\bin\Debug\InOne.Invision.AlertProcessing.dll" to "bin\InOne.Invision.AlertProcessing.dll". The process cannot access the file 'bin\InOne.Invision.AlertProcessing.dll' because it is being used by another process. InVision2 Error 168 Unable to copy file "C:\InOne\Common\InVision.BusinessLogic\bin\Debug\InVision.BusinessLogic.dll" to "bin\InVision.BusinessLogic.dll". The process cannot access the file 'bin\InVision.BusinessLogic.dll' because it is being used by another process. InVision2 Error 169 Unable to copy file "C:\InOne\Common\InVision.Common\bin\Debug\InVision.Common.dll" to "bin\InVision.Common.dll". The process cannot access the file 'bin\InVision.Common.dll' because it is being used by another process. InVision2 Error 170 Unable to copy file "C:\InOne\Data\bin\Debug\InVision.Data.dll" to "bin\InVision.Data.dll". The process cannot access the file 'bin\InVision.Data.dll' because it is being used by another process. InVision2 Error 171 Unable to copy file "C:\InOne\Common\InVision.DataAccessLayer\bin\Debug\InVision.DataAccessLayer.dll" to "bin\InVision.DataAccessLayer.dll". The process cannot access the file 'bin\InVision.DataAccessLayer.dll' because it is being used by another process. InVision2 Error 172 Unable to copy file "C:\InOne\Common\InVision.DataAccessLayer.SqlClient\bin\Debug\InVision.DataAccessLayer.SqlClient.dll" to "bin\InVision.DataAccessLayer.SqlClient.dll". The process cannot access the file 'bin\InVision.DataAccessLayer.SqlClient.dll' because it is being used by another process. InVision2
错误 165 无法将文件“C:\InOne\Common\DexProcessor\bin\Debug\DexProcessor.dll”复制到“bin\DexProcessor.dll”。该进程无法访问文件“bin\DexProcessor.dll”,因为它正被另一个进程使用。InVision2 错误 166 无法将文件“C:\InOne\Common\DexParser\bin\Debug\InOne.DexParser.dll”复制到“bin\InOne.DexParser.dll”。该进程无法访问文件“bin\InOne.DexParser.dll”,因为它正被另一个进程使用。InVision2 错误 167 无法将文件“C:\InOne\Common\AlertProcessor\bin\Debug\InOne.Invision.AlertProcessing.dll”复制到“bin\InOne.Invision.AlertProcessing.dll”。该进程无法访问文件“bin\InOne.Invision.AlertProcessing.dll”,因为它正被另一个进程使用。InVision2 错误 168 无法将文件“C:\InOne\Common\InVision.BusinessLogic\bin\Debug\InVision.BusinessLogic.dll”复制到“bin\InVision.BusinessLogic.dll”。该进程无法访问文件“bin\InVision.BusinessLogic.dll”,因为它正被另一个进程使用。InVision2 错误 169 无法将文件“C:\InOne\Common\InVision.Common\bin\Debug\InVision.Common.dll”复制到“bin\InVision.Common.dll”。该进程无法访问文件“bin\InVision.Common.dll”,因为它正被另一个进程使用。InVision2 错误 170 无法将文件“C:\InOne\Data\bin\Debug\InVision.Data.dll”复制到“bin\InVision.Data.dll”。该进程无法访问文件“bin\InVision.Data.dll”,因为它正被另一个进程使用。InVision2 错误 171 无法将文件“C:\InOne\Common\InVision.DataAccessLayer\bin\Debug\InVision.DataAccessLayer.dll”复制到“bin\InVision.DataAccessLayer.dll”。该进程无法访问文件“bin\InVision.DataAccessLayer.dll”,因为它正被另一个进程使用。InVision2 错误 172 无法将文件“C:\InOne\Common\InVision.DataAccessLayer.SqlClient\bin\Debug\InVision.DataAccessLayer.SqlClient.dll”复制到“bin\InVision.DataAccessLayer.SqlClient.dll”。该进程无法访问文件“bin\InVision.DataAccessLayer.SqlClient.dll”,因为它正被另一个进程使用。视觉2 DataAccessLayer.dll',因为它正被另一个进程使用。InVision2 错误 172 无法将文件“C:\InOne\Common\InVision.DataAccessLayer.SqlClient\bin\Debug\InVision.DataAccessLayer.SqlClient.dll”复制到“bin\InVision.DataAccessLayer.SqlClient.dll”。该进程无法访问文件“bin\InVision.DataAccessLayer.SqlClient.dll”,因为它正被另一个进程使用。视觉2 DataAccessLayer.dll',因为它正被另一个进程使用。InVision2 错误 172 无法将文件“C:\InOne\Common\InVision.DataAccessLayer.SqlClient\bin\Debug\InVision.DataAccessLayer.SqlClient.dll”复制到“bin\InVision.DataAccessLayer.SqlClient.dll”。该进程无法访问文件“bin\InVision.DataAccessLayer.SqlClient.dll”,因为它正被另一个进程使用。视觉2
This just started happening a week ago and is very annoying... I have to go into the web app's bin folder and delete the pdb files and then it'll let me delete the dll's most of the time. Every once in a while it doesn't let me so I have to close Visual Studio and then it lets me delete them. I checked and it's Visual Studio (devenv) that is locking the dll's. Rebooting the machine doesn't help.
这刚开始发生在一周前,非常烦人......我必须进入网络应用程序的 bin 文件夹并删除 pdb 文件,然后它会让我在大部分时间删除 dll。每隔一段时间它就不允许我,所以我必须关闭 Visual Studio,然后它让我删除它们。我查了一下,是 Visual Studio (devenv) 锁定了 dll。重新启动机器没有帮助。
This is really reducing my productivity, is there anything I can do to resolve this?
这确实降低了我的工作效率,我可以做些什么来解决这个问题?
As mentioned, Visual Studio 2008 (devenv.exe) is the process locking the DLLs.
如前所述,Visual Studio 2008 (devenv.exe) 是锁定 DLL 的进程。
I noticed something... When it compiles successfully, it's copying all the DLLs into the bin folder, then they are all deleted, then a new set are copied into the bin. When it isn't successfull, the first set of DLLs are copied in, then it fails. So it seems to be using the bin folder for 2 things when it should only be for 1. Does this help??
我注意到了一些事情...当它编译成功时,它会将所有的 DLL 复制到 bin 文件夹中,然后将它们全部删除,然后将一组新的 DLL 复制到 bin 中。如果不成功,则复制第一组 DLL,然后失败。所以它似乎将 bin 文件夹用于 2 件事,而它应该只用于 1 件事。这有帮助吗??
采纳答案by Justin
The issue ended up being that in the web.config someone had added:
问题最终是有人在 web.config 中添加了:
hostingEnvironment shadowCopyBinAssemblies="false"
After commenting this out, everything started building ok. What a nightmare!!
注释掉这一点后,一切都开始正常了。什么样的恶梦!!
回答by Ben S
Use ProcessExplorerto find out what process has the file openand go from there.
使用ProcessExplorer来找出进程打开了该文件,并从那里走。
If a process is currently using those DLL, you can't delete and re-write it. You'll have to kill or otherwise stop the process using those DLLs while you compile.
如果进程当前正在使用这些 DLL,则无法删除和重写它。您必须在编译时终止或以其他方式停止使用这些 DLL 的进程。
回答by Developer22222222
I have battled this issue FOR YEARS!
我多年来一直在与这个问题作斗争!
Have you tried adding this to your PREBUILD Event?
您是否尝试将其添加到您的 PREBUILD 事件中?
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
See this for more info: http://nayyeri.net/file-lock-issue-in-visual-studio-when-building-a-project
有关更多信息,请参阅:http: //nayyeri.net/file-lock-issue-in-visual-studio-when-building-a-project
Here's another thread, with more things to try...
这是另一个线程,有更多的东西可以尝试......
回答by Marcel Gheorghita
What worked for me is the following pre-build event:
对我有用的是以下预构建事件:
if exist "$(TargetPath).locked.bak" del "$(TargetPath).locked.bak"
if exist "$(TargetPath).bak" del "$(TargetPath).bak"
if exist "$(TargetPath).locked" ren "$(TargetPath).locked" "$(TargetFileName).locked.bak"
if exist "$(TargetPath)" ren "$(TargetPath)" "$(TargetFileName).bak"
What I have noticed in my case is that the 2 files are being created and can not be deleted. You can, however, rename them (and they are still in use if you try to delete them). On a next build, the renamed files are no longer in use (lock removed) and they can be deleted, which is what the above script does, after which it can safely rename the new locked files so there will be no problems in generating the build output.
在我的情况下,我注意到这 2 个文件正在创建并且无法删除。但是,您可以重命名它们(如果您尝试删除它们,它们仍在使用中)。在下一次构建中,重命名的文件不再被使用(锁被移除)并且它们可以被删除,这就是上面的脚本所做的,之后它可以安全地重命名新的锁定文件,因此在生成文件时不会出现问题构建输出。
The other pre-build events posted here and in other places did not help me a lot (they worked only for one extra build or only a few before the problem arose again). So now I am currently using the one posted above for my debugging purposes.
此处和其他地方发布的其他预构建事件对我没有太大帮助(它们仅适用于一个额外构建或仅在问题再次出现之前仅用于少数几个构建)。所以现在我目前正在使用上面发布的一个来进行调试。
回答by rwg
I just wanted to say that this problem started with me today. (VS 2010, C#) I have been working on this program for a month without this problem, now today it started. I start VS, change code, compile and test and quit program. Make another change, compile and BOOM Unable to copy file "obj\x86\Debug\progname.exe" to "bin\Debug\progname.exe" because if is being used by another process.
我只想说这个问题从我今天开始。(VS 2010, C#) 我已经在这个程序上工作了一个月没有这个问题,今天它开始了。我启动VS,更改代码,编译和测试并退出程序。再次更改,编译和 BOOM 无法将文件“obj\x86\Debug\progname.exe”复制到“bin\Debug\progname.exe”,因为如果正在被另一个进程使用。
ProcExp shows only Visual Studio (actually devenv.exe) using this file. There is only one instance of VS running. There are two listing on my debug\progname.exe, one is a Type DLL, the other is a Type handle.
ProcExp 仅显示使用此文件的 Visual Studio(实际上是 devenv.exe)。只有一个 VS 实例在运行。我的 debug\progname.exe 上有两个列表,一个是 Type DLL,另一个是 Type 句柄。
Using devenv /ResetSettings did not resolve anything, but wasted 10 minutes putting everything back to my desired view.
使用 devenv /ResetSettings 没有解决任何问题,但浪费了 10 分钟将所有内容恢复到我想要的视图。
Using the PREBUILD events rename trick mentioned above solves the problem for a couple of changes, but on the next change the "exe.locked" file is locked and cannot be deleted. Then the rename fails.
使用上面提到的 PREBUILD 事件重命名技巧可以解决一些更改的问题,但是在下一次更改时,“exe.locked”文件被锁定并且无法删除。然后重命名失败。
The debug\progname.exe file name remains locked even after closing the project.
即使关闭项目后,debug\progname.exe 文件名仍保持锁定状态。
Closing VS, manually delete the files in the debug folder, opening VS and my solution, then Build->Clean Solution seems to work for me, at least its working now after I did all of that stuff.
关闭 VS,手动删除调试文件夹中的文件,打开 VS 和我的解决方案,然后 Build->Clean Solution 似乎对我有用,至少在我完成所有这些工作后它现在可以工作了。
Hope this helps -rwg
希望这有帮助 -rwg
回答by Craig Nichols
I didn't have any luck with the pre-build events unfortunately. What worked, in typical IT Crowd fashion, was to quit Visual Studio and reopen it.
不幸的是,我对预构建事件没有任何运气。以典型的 IT Crowd 方式,退出 Visual Studio 并重新打开它是有效的。
回答by Martin Lütken
Easy fix for Windows 7: Start the service "Application Experience" . Search for "Services" in "Control Panel".
轻松修复 Windows 7:启动“应用程序体验”服务。在“控制面板”中搜索“服务”。
-Martin
-马丁
回答by Rajesh Toleti
If you have Visual Nunit, it must be locking dll file.
如果你有 Visual Nunit,它必须锁定 dll 文件。
- Close VS
- Go to taks manager , kill the Visual Nunit process
- Now open VS and build the project
- 关闭VS
- 转到 taks manager ,杀死 Visual Nunit 进程
- 现在打开VS并构建项目
回答by learn_andrd
Just go to \Debug\bin and delete all .dll files.
只需转到 \Debug\bin 并删除所有 .dll 文件。
Working great for me.
对我来说很棒。
回答by tags2k
I had this issue on a web project with System.Web.Extensions.dll from the Microsoft Reference Assemblies folder. Setting "Copy Local" to false in the reference properties fixed it.
我在 Microsoft Reference Assemblies 文件夹中使用 System.Web.Extensions.dll 的 Web 项目中遇到了这个问题。在参考属性中将“Copy Local”设置为 false 修复了它。

