Visual Studio中无法写入输出文件'... \ OBJ \调试\ Foo.Bar.dll"文件、Visual、Studio、OBJ

2023-09-03 00:50:44 作者:薄情的世界深情的活着

我得到这个错误在编译在Visual Studio 2010中的大C#的解决方案。 每次编译后,我不得不删除一个使用该解决方案项目的obj文件夹。否则,我得到了以下错误:

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:

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.

使用的 pre-构建脚本作为OBJ文件夹中去除,这个特殊的解决方案是可以接受的,但如果发行项目是一个广泛使用的库的重新编译会导致父母的重新编译其他一些人项目。

Some other people used pre-build scripts for 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.

推荐答案

最后,我发现这个 VS2010 解决方案(SP1太)错误,我想用计算器用户共享

Finally I've discovered a solution for this VS2010 (SP1 too) "bug" and I want to share it with stackoverflow users.

在我的情况下,问题是,的csproj文件是自引用锁定'... \ OBJ \调试\ Foo.Bar.dll文件。疯狂,我知道了。

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 .csproj file:

<Reference Include="Foo.Bar">
  <HintPath>obj\Debug\Foo.Bar.dll</HintPath>
</Reference>