本文介绍了由于名称相同,无法添加引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自从更新到 VS 2013 以来,我的行为无法添加对 2 个同名项目的引用.我做了以下事情:

Since the update to VS 2013 I have the behaviour that I cannot add a reference to 2 projects with the same name. I did the following:

  1. 添加了 3 个解决方案文件夹 A、B 和 C.
  2. 在 A 和 B 文件夹中添加了类库Core"类型的项目.
  3. 将 ConsoleApplication 类型的项目添加到文件夹 C.

生成的结构如下所示:

Solution
 + A
   + Core
 + B
   + Core
 + C
   + ConsoleApp

在 A 的项目属性中输入以下内容:

In the project properties of A the following is entered:

  • 程序集名称:A.Core
  • 默认命名空间:A.Core

在 B 中:

  • 程序集名称:B.Core
  • 默认命名空间:B.Core

在 C.ConsoleApp 中添加对 A.Core 的引用并尝试将 B.Core 引用到控制台后,出现错误:

After I added a reference to A.Core in C.ConsoleApp and I try to reference to B.Core to the console I get the error:

无法添加对Core (B.Core)"的引用.项目中已存在对组件Core"的引用.

该解决方案是使用 VS 2012 创建的,并在升级后显示了此行为.我必须在控制台内设置什么?

The solution was created with VS 2012 and shows this behavior since upgrade. What do I have to setup inside the console?

我在 Youtube 上发布了一个截屏视频来解释这个问题,并在 微软支持.我仍然认为,这是一个错误.

I published a screencast on Youtube to explain the problem and placed a bug at Microsoft-Support. I still think, this is a bug.

推荐答案

问题是引用名称与项目名称相同.它仍然通过适当的名称(A.Core.dll 或 B.Core.dll)引用 DLL,但引用使用 VS 中的项目名称:

The issue is that the reference name takes on the project name. It's still referencing the DLL by the appropriate name (A.Core.dll or B.Core.dll), but the reference uses the project name inside VS:

如果您在添加对 A.Core 的引用后查看项目文件,您会看到:

If you look at the project file after adding a reference to A.Core, you'll see this:

<ProjectReference Include="..ClassLibrary1Core.csproj">
  <Project>{16c42795-f703-4673-98e4-98758c09f9e0}</Project>
  <Name>Core</Name>
</ProjectReference>

将 Name 值更改为 A.Core,您将被解锁.(B.Core 仍会显示为Core",直到您对其进行编辑.)

Change the Name value to A.Core and you'll be unblocked. (B.Core will still show up as "Core" until you edit it as well.)

这篇关于由于名称相同,无法添加引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 06:30