André Carlucci

Skeptic .net development

How to add a project reference to a .net core library from another solution

I was debugging one .net core application and to solve a problem I had to change the code in the application and in a referenced .net core library at the same time.

One way to achieve this when both are in the same solution is to reference the library setting its target as project in the project.json file. Something like this:

That’s easy and it’s going to work by default if both projects have the same parent folder. Ex:

This works:

/SolutionA/Project1/project.json
/SolutionA/Project2/project.json

But this doesn’t:

/SolutionA/SomeDir/Project1/project.json
/SolutionA/SomeOtherDir/Project2/project.json

One way to go around this limitation and also reference any project in your computer is to add its folder to the current solution in the global.json file:

You can use relative or absolute paths. Once you do that, add the project as reference the same way you did with the local library:

And you’re all set.
Note, the renormally ferenced project will also appear in your solution explorer. Happy debugging :)