visual-studio VisualStudio2010 调试 - 进程无法访问文件......因为它正被另一个进程使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2690119/
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
VisualStudio2010 Debugging - The process cannot access the file ... because it is being used by another process
提问by Richard Forss
I'm unable to debug a WinForms C# application using the released version of Visual Studio 2010 Prof.
我无法使用 Visual Studio 2010 Prof. 的已发布版本调试 WinForms C# 应用程序。
I get the following error message after the second debugging run.
第二次调试运行后,我收到以下错误消息。
Error 9 Unable to copy file "obj\x86\Debug\Arrowgrass Reports.exe" to "bin\Debug\Arrowgrass Reports.exe". The process cannot access the file 'bin\Debug\Arrowgrass Reports.exe' because it is being used by another process.
错误 9 无法将文件“obj\x86\Debug\Arrowgrass Reports.exe”复制到“bin\Debug\Arrowgrass Reports.exe”。该进程无法访问文件“bin\Debug\Arrowgrass Reports.exe”,因为它正被另一个进程使用。
I've tried a pre-build script to attempt to delete this file, but it's locked by Visual Studio.
我尝试了一个预构建脚本来尝试删除此文件,但它已被 Visual Studio 锁定。
There are a few references to this on the net so it is a know problem. Does anyone have a hotfix or effective work-around?
网络上有一些对此的引用,因此这是一个已知问题。有没有人有修补程序或有效的解决方法?
采纳答案by DocKell
I have found this issue very easy to reproduce, and the fix for me is a variation on Richard Fors' answer. If I have a UserControl open in the designer, run the debugger, and then edit the UserControl, the subsequent rebuild will fail. If I close the UserControl before running the debugger I never get this error, so I just make sure to close the designer window before hitting F5.
我发现这个问题很容易重现,对我来说修复是对 Richard Fors 的回答的一个变体。如果我在设计器中打开了 UserControl,运行调试器,然后编辑 UserControl,则后续重建将失败。如果我在运行调试器之前关闭 UserControl,我永远不会收到此错误,因此我只需确保在按 F5 之前关闭设计器窗口。
回答by Alex. S.
As of October 2012, I still have that issue so the VS 2010 SP1 didn't solve the problem. What I did, and worked consistently, was disabling the hosting process in the projects.
到 2012 年 10 月,我仍然有这个问题,所以 VS 2010 SP1 没有解决问题。我所做的并始终如一地禁用了项目中的托管过程。
To disable the hosting process:
要禁用托管进程:
. Open a project in Visual Studio.
. On the Project menu, click Properties.
. Click the Debug tab.
. Clear the Enable the Visual Studio hosting process check box.
Source: http://msdn.microsoft.com/en-us/library/ms185330(v=vs.100).aspx
来源:http: //msdn.microsoft.com/en-us/library/ms185330(v=vs.100).aspx
回答by Dirk Vollmar
You can try to kill the vshost.exe process:
您可以尝试杀死 vshost.exe 进程:
taskkill /F /IM "Arrowgrass Reports.vshosts.exe"
You might also be lucky and simply be able to move the file in question. Moving the file can be done by adding the following lines of code to the pre-build event of your project:
您也可能很幸运,只需能够移动有问题的文件。可以通过将以下代码行添加到项目的预构建事件中来移动文件:
if exist "$(TargetPath).locked" del "$(TargetPath).locked"
if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"
回答by Joe C
Disabling windows search did not fix for me. However disabling Antivirus did (our Antivirus is Symantec Endpoint Protection 11)
禁用 Windows 搜索并没有解决我的问题。但是禁用了防病毒软件(我们的防病毒软件是 Symantec Endpoint Protection 11)
As such, I was able to fix this for myself by changing the Debug settings in the project to point the working folder to a path on the C: drive, and then excepting that path from the antivirus auto-protect scan settings.
因此,我可以通过更改项目中的调试设置来将工作文件夹指向 C: 驱动器上的路径,然后从防病毒自动保护扫描设置中排除该路径,从而为自己解决此问题。
I hope this helps someone.
我希望这可以帮助别人。
回答by Tom Studee
I posted this answer in a similar question but figured I'd also say it here:
我在一个类似的问题中发布了这个答案,但我想我也会在这里说:
Alright... this might sound pretty crazy.
好吧……这听起来可能很疯狂。
I've had this problem in VS2010 for the last couple of years. The workaround mentioned here works for me, but a lot of times I forgot to close all my forms/usercontrols first.
在过去的几年里,我在 VS2010 中遇到了这个问题。这里提到的解决方法对我有用,但很多时候我忘记先关闭所有表单/用户控件。
I've discovered that merely going to view the open files via:
我发现只需通过以下方式查看打开的文件:
Computer Management (compmgmt.msc)->Shared Folders->Open Files
Computer Management (compmgmt.msc)->Shared Folders->Open Files
will "Free up" whichever file is being locked. Very strange, but it works for me!
将“释放”任何被锁定的文件。很奇怪,但它对我有用!
回答by Manish Dubey
In my case, I did Project Properties-->Security Tab-->Uncheck Click-Once security settings (If it is checked). It worked for me. In my project, it was showing this error for a C++ dll being used in my C# project.
就我而言,我做了项目属性--> 安全选项卡--> 取消选中 Click-Once 安全设置(如果选中)。它对我有用。在我的项目中,它为我的 C# 项目中使用的 C++ dll 显示了此错误。
回答by Mark Groenewald
I cant' write to a comment since not at 50 points but for me I excluded my project folder in ESET Enpoint Security ver 5. Seems like it blocked/hogged some files. My Error did not state which exe or file was in use so it took a long time to finally get to what JoeC said about Antivirus and tried it. Seems to be working now (Visual Studio 2010 SP1)
我不能写评论,因为不是 50 点,但对我来说,我在 ESET Enpoint Security 版本 5 中排除了我的项目文件夹。似乎它阻止/占用了一些文件。我的错误没有说明正在使用哪个 exe 或文件,所以花了很长时间才最终了解 JoeC 所说的关于 Antivirus 的内容并尝试了它。现在似乎正在工作(Visual Studio 2010 SP1)
回答by oshan2csd
Closing recently changed User Controlssolved the problem in my scenario. Hope this will help somebody out there.
关闭最近更改的用户控件解决了我的场景中的问题。希望这会帮助那里的人。
回答by Tomas Andersson
Got the error ("The process cannot access the file … because it is being used by another process") when I modified the (Visual Studio 2010 C# Express with SP1) solution from two large (10 source files, ~500 lines per file) projects with one referencing the other, to lots (6) of smaller projects with lots of projects referencing other projects.
当我从两个大型(10 个源文件,每个文件约 500 行)修改(Visual Studio 2010 C# Express with SP1)解决方案时出现错误(“该进程无法访问文件......因为它正被另一个进程使用”)一个引用另一个的项目,到许多 (6) 个较小的项目,其中许多项目引用其他项目。
The references were to the dll- and exe files (the Debug versions of them), NOT to the projects even though the projects were in the same solution.
引用的是 dll- 和 exe 文件(它们的调试版本),而不是项目,即使项目在同一个解决方案中。
I then learned that references should be to projects, not files, for F12 to work properly. So I modified the references. That made F12 work (jump to the source file instead of some auto-generated interface description), and at the same time the "cannot access file" error during build disappeared.
然后我了解到引用应该是项目,而不是文件,以使 F12 正常工作。所以我修改了参考资料。这使得 F12 工作(跳转到源文件而不是一些自动生成的界面描述),同时构建过程中的“无法访问文件”错误消失了。
I only got the "cannot access file" error when doing Release builds. The references were to the Debug versions of exe/dll's. I suspect that this mixing is what triggers the bug in VS.
在进行发布版本时,我只收到“无法访问文件”错误。引用的是 exe/dll 的调试版本。我怀疑这种混合是触发 VS 错误的原因。
回答by Tidjani Belmansour
I encountered this issue when developing windows services. I found out that it happens when the service is running. Thus, you only need to stop the service (from the services.msc console) and you're good to go !
我在开发 windows 服务时遇到了这个问题。我发现它在服务运行时发生。因此,您只需要停止服务(从 services.msc 控制台)就可以了!
Hope this helps. Tidjani.
希望这可以帮助。蒂贾尼。

