Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
217 views
in Technique[技术] by (71.8m points)

c# - Reference could not be added because of same name

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. Added 3 solution folders A, B and C.
  2. Added a project of type class library "Core" to both A and B folder.
  3. Added a project of type ConsoleApplication to folder C.

The resulting structure looks like this:

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

In the project properties of A the following is entered:

  • Assembly name: A.Core
  • Default namespace: A.Core

and in B:

  • Assembly name: B.Core
  • Default namespace: 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:

A reference to 'Core (B.Core)' could not be added. A reference to the component 'Core' already exists in the project.

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here

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>

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.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...