好吧,我之前已经遇到过这个问题一百万次了,而且之前已经被回答过 100 万+1 次了。
然而,再一次。我有 3 个项目,A、B 和 C,每个项目都有一个 DLL。每个项目都是.Net 4.0(不是客户端构建,完整的4.0)。项目 C 引用 A 和 B。它们被作为项目引用,并且输出设置为本地复制。
在 C 中,我的 .cs 文件中有两个 using 语句:
using A;
using B;
当我编译时,我得到的抱怨是找不到B。A没问题。 B 取决于 A。
我到底该怎么办?我删除并重新添加,关闭VS2010,重新打开它,查看.csproj文件。我就是无法得到它。又是第一百万次。
请有人给我足够的理智,让我一劳永逸地了解这个来源!
是的,这可能在 StackOverflow 的某个地方得到了答案,但在我迄今为止检查过的任何最佳答案中都没有。这些术语太通用了,无法使用,太多问题的答案是“呃,添加参考文献”。我已经过了那个阶段了。
这是我得到的错误。有3种,但从以往的经验来看,最后一种才是真正的。
Error 130 'AWI.WWG.EXPMRI.MriUpload.Data.MriUpload' does not contain a definition for 'Database' and no extension method 'Database' accepting a first argument of type 'AWI.WWG.EXPMRI.MriUpload.Data.MriUpload' could be found (are you missing a using directive or an assembly reference?)
Error 114 'object' does not contain a definition for <blah>
Error 59 The type or namespace name '<blah>' could not be found (are you missing a using directive or an assembly reference?)
啊哈,我查看了警告,而不仅仅是错误,这是我看到的:
Warning 69 The referenced project '..\..\..\..\..\..\..\Partners\integration\framework\connectors\Partners.Connectors.Base\Partners.Connectors.Base\Partners.Connectors.Base.2010.csproj' does not exist. AWI.WWG.EXPMRI.MriUpload.Objects
在本例中,该 .csproj 文件是“B”。即使我删除并重新添加项目引用,我还是得到了这个。但我感觉我离自己越来越近了!
嗯,我刚刚找到了另一个 DLL,将其命名为“D”,“A”引用了它。当我将其添加到项目中时,我开始收到抱怨:
----------------
The Add Reference Dialog could not be shown due to the error:
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
----------------
这可能是相关的,还是只是另一种干扰?
好吧,我发现了这个问题,虽然我不明白。
当我通过 IDE 添加引用时,它会将其添加到“C”的 csproj 文件中:
<ProjectReference Include="..\..\..\..\..\..\..\Partners\integration\framework\connectors\Partners.Connectors.Base\Partners.Connectors.Base\Partners.Connectors.Base.2010.csproj">
这不会编译,它警告找不到引用的项目,然后所有这些错误都会发生。但后来我将 ProjectReference 更改为以下内容:
<ProjectReference Include="C:\...\Partners.Connectors.Base.2010.csproj">
...而且效果很好。请注意,这些路径的长度都不接近 256 个字符。完全合格的只有 135 个字符。但也许 IDE 正在对路径进行一些愚蠢的修饰。