Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net Core Project Reference Inheritance [duplicate]

I noticed when using .net core 2.2 if you add a project reference to another project those project references are available to other projects that reference the original project.

For example:

If you have a 3 projects, let's say UI, Services, and DAL. If you have a reference to Services from UI and Services has a reference to DAL. With that set up, you will notice you will be able to add a using statement and gain access to classes in the DAL project from the IU project. Whats the reasoning behind this and can it be disabled?

UI
-- project references
---- Services

Services
-- project references
---- DAL

like image 394
mluker Avatar asked Nov 06 '22 15:11

mluker


1 Answers

I took @Kirk Larkin comment and made it work for me, however I had to use "ExcludeAssets" instead:

Imagine something like this:

-- GUI

---- Business layer dll

------ Data access layer dll

Inside the Business layer dll project file (csproj):

<ProjectReference Include="..\..\DALProject\DALProject\DALProject.csproj">
  <ExcludeAssets>compile</ExcludeAssets>
</ProjectReference>

With this, I can no longer reference DALProject methods from my GUI layer where it's not directly referenced. This method also includes all the supporting DLL's for runtime use.

Hope this helps.

like image 83
Michael Woolsey Avatar answered Nov 25 '22 19:11

Michael Woolsey