user9993
user9993

Reputation: 6180

Unable to add project reference in Visual Studio 2015

I previously asked a similar question regarding Visual Studio 2013 but now I'm running into the same problem with Visual Studio 2015 but it seems to work differently, which makes the previous answer not applicable to this question. This is my previous question: Visual Studio 2013 - How to debug a project within a solution

I'm attempting to add a project reference. I have a library I'm working on in a separate solution/project and a console application I want to use to test and debug the library.

I tried: Add Reference > Projects > Solution > Browse

But the open file dialog does not contain .sln files in the filter list and if I force it to display them by typing *.sln and then select the Solution I get:

"Please make sure the file is accessible and that it is a valid assembly or COM component."

What am I doing wrong? How do I properly add a Solution/Project reference?

enter image description here

Upvotes: 21

Views: 50051

Answers (8)

Eric Moon
Eric Moon

Reputation: 131

I had this problem today and I looked at the configuration manager for the solution. The projects had different platform settings. I made them both Any CPU and rebuilt. Then I could reference the project.

Upvotes: 0

spacebread
spacebread

Reputation: 541

I ended up having a different solution. I had three projects in the solution which referenced a NuGet package which was no longer available. I had the library locally but I was unable to add it. I found that because of the BUILD ORDER and DEPENDENCY of my projects, I had to add it to the project that was built first, then I could add it to the projects that were dependent on that project.

Upvotes: 0

Medeni Baykal
Medeni Baykal

Reputation: 4333

You should add project to your solution first; after adding project to your solution, you can reference it.

To add an existing project to your solution:

You can add it from <code>File > Add > Existing Project</code> menu...

Add reference menu:

Expand the project from Solution Explorer, and right click the <code>References</code> folder then select <code>Add reference...</code>

Add references dialog:

Expand the <code>Projects</code> from left side menu, and select <code>Projects</code>.

Upvotes: 2

David Coster
David Coster

Reputation: 1805

For me issue was due to a difference in the types of projects. One was a C# Windows forms project and the other project was a C# Universal Windows project.

The Windows Forms project couldn't reference the Universal Windows project. The error was "Unable to add a reference to project "XYZ".

It appears you can have a library shared between both types of projects by folloing this answer: What kind of class library works with both Universal and Winform projects?

Upvotes: 1

NidhinSPradeep
NidhinSPradeep

Reputation: 1304

For me issue was due to difference in Target framework. One was .NET Framework 4.5 and other was .NET Framework 4.5.2

Verify if the Target framework is same for your project and the project reference that you are trying add reference.

(Right click on project -> properties -> Application Tab(Target frame work))

Upvotes: 29

melston
melston

Reputation: 2352

In case anyone else runs into this here is something that I found. I had almost the exact same issue in VS 2015. I created a console app and then a class library project but could not add a reference to the class library.

It turns out I didn't create a class library project as I had thought, but rather a class library (package) project. These are different things and I was unaware of what the (package) part meant when I selected it. This is for creating Nuget packages, apparently.

I'm not sure if this is something new to VS 2015 but I had not run across it before and it caused me some grief. The error message ('A reference to ClassLibrary1 could not be added') was totally worthless in trying to debug it.

Upvotes: 9

Pylyp Lebediev
Pylyp Lebediev

Reputation: 2131

Right click on your solution file in Solution Explorer window, click Add and select Existing Project...

enter image description here

Once the project is a part of the solution, you will be able to add project reference.

Upvotes: 13

Daniel A. White
Daniel A. White

Reputation: 191037

In order to add a project reference, the project has to be part of the solution.

Upvotes: 1

Related Questions