C# Visual Studio 无法写入输出文件“...\obj\Debug\Foo.Bar.dll”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12301625/
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 write to output file '...\obj\Debug\Foo.Bar.dll"
提问by Salaros
I've got this error while compiling a big c# solution in Visual Studio 2010. Each time after compilation I had to delete obj folder of one the projects used by this solution. Otherwise I got the following error:
我在 Visual Studio 2010 中编译大型 c# 解决方案时遇到此错误。每次编译后,我都必须删除此解决方案使用的项目之一的 obj 文件夹。否则我收到以下错误:
Could not write to output file '...\obj\Debug\Foo.Bar.dll'
The process cannot access the file because it is being used by another process
I've was looking for a solution all over the Internet and actually found/tried few of them.
我一直在互联网上寻找解决方案,实际上找到/尝试了其中的几个。
For example : a lot of people on dev forums were suggesting not to start the compilation while UserControl(in some other sources From) designer is opened.
例如:在开发论坛,很多人都建议不开始编译,而用户控件(在一些其他来源从设计师打开)。
Some other people used pre-build scriptsfor obj folder removal, this particular solution is acceptable, but if the issued project is a widely used library its recompilation will cause recompilation of "parent" projects.
其他一些人使用预构建脚本来删除 obj 文件夹,这个特定的解决方案是可以接受的,但是如果发布的项目是一个广泛使用的库,它的重新编译将导致“父”项目的重新编译。
采纳答案by Salaros
Finally I've discovered a solution for this VS2010(SP1 too) "bug" and I want to share it with stackoverflow users.
最后,我发现了这个VS2010(也是 SP1)“bug”的解决方案,我想与 stackoverflow 用户分享。
In my case the problem was that csproj file was SELF-REFERENCING the locked '...\obj\Debug\Foo.Bar.dll'file. Crazy I know.
So I solved this annoying issue by removing the following line from .csprojfile:
就我而言,问题在于 csproj 文件是自引用锁定'...\obj\Debug\Foo.Bar.dll'文件。疯了我知道。所以我通过从.csproj文件中删除以下行来解决这个烦人的问题:
<Reference Include="Foo.Bar">
<HintPath>obj\Debug\Foo.Bar.dll</HintPath>
</Reference>
回答by Marcel
I initially found another solution to the problem as VS seems to lock the assembly in the obj\debug folder. I added a pre-build script to the project which fixed my problem.
我最初找到了另一个解决此问题的方法,因为 VS 似乎将程序集锁定在 obj\debug 文件夹中。我在项目中添加了一个预构建脚本来解决我的问题。
del "$(ProjectDir)obj\*.*" /S /F /Q
After seeing the answer given by Salaros, that was indeed the problem. I created a new usercontrol that uses a Server control from another project. For some reason VS sometimes creates a self-references to itself when you view the usercontrol in design mode. Even removing the self-reference fixes it until VS thinks its time to add the reference again. Haven't found an exact pattern for that part.
看到萨拉罗斯给出的答案,确实是这个问题。我创建了一个新的用户控件,它使用另一个项目中的服务器控件。出于某种原因,当您在设计模式下查看用户控件时,VS 有时会创建对自身的自引用。即使删除自引用也会修复它,直到 VS 认为是时候再次添加引用了。尚未找到该部分的确切模式。
PS: I'm using vs2012
PS:我在用 vs2012
回答by usama el-far
This problem happened to me when I:
这个问题发生在我身上时:
- Opened Visual Studio
- Ran debug
- Went to C: and used system cleanup
- 打开 Visual Studio
- 跑调试
- 转到 C: 并使用系统清理
If you try to build again, you will find this error.
如果再次尝试构建,则会发现此错误。
Solution:
解决方案:
- Close Visual Studio
- Do system cleanup
- Restart your computer
- Open Visual Studio as administrator
- Choose your project
- Clean
- Rebuild
- 关闭 Visual Studio
- 进行系统清理
- 重启你的电脑
- 以管理员身份打开 Visual Studio
- 选择您的项目
- 干净的
- 重建
回答by Grayson
In my case for me somehow the exe file was missing from release. Not sure how this happened. I replace it with a copy from debug and all was fine. I should have checked this sooner but never thought that the file would just turn up missing.
就我而言,不知何故,发行版中缺少 exe 文件。不知道这是怎么发生的。我用调试中的副本替换它,一切都很好。我应该早点检查这个,但从没想过文件会丢失。

