Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing another project in .Net Core

I have 6 projects in a blank solution. I just want to reference a project to another. I have HomeController in Blog.Web projects. I want to access another project's methods like IOrganizationService in Blog.Services projects. How can I use IOrganization's method in HomeController class? For clear insight, please see picture. enter image description here

Red marks show the errors....

like image 356
orbit Avatar asked Jun 20 '17 11:06

orbit


People also ask

How do I add a project reference in net core project?

One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.

Can two projects reference each other?

This can be achieved by adding reference of one project in the other project. If both the projects are in the same solution, then expand the project name, right click on 'References', click on Add references. Go to 'Projects' Tab, select the project name which you want to use in current project, click ok.


1 Answers

It looks like you've created everything as web sites, but I suspect that most of those projects should actually be class libraries (dlls), not sites. You might need to reset a few things!

You should be able to right-click on the Dependencies node to add a project reference: enter image description here

or the project node:

enter image description here

then:enter image description here

Alternatively: edit the csproj and add a <ProjectReference> node:enter image description here

like image 59
Marc Gravell Avatar answered Nov 04 '22 09:11

Marc Gravell