Andrew
Andrew

Reputation: 1259

ASP.Net Core allows chained project referencing

Before ASP.Net Core:

With this reference structure, MVC cannot access classes in the Lib2 project, which is as expected and what I want.

The same project and reference structure in ASP.Net Core: MVC can access classes in Lib2. Looking at the MVC/References node in the Solution Explorer in Visual studio, you can see MVC/References/DNX 4.5.1/Lib1 - so far so good (I did add a reference to Lib1 from MVC) - but then I can expand the Lib1 node, and will see Lib2 under it. End result: MVC can access Lib2 classes via a reference chain.

I presume this behaviour is by design, but then how can I achieve the old behaviour? I do not want developers to be able to access Lib2 classes from MVC.

Upvotes: 2

Views: 355

Answers (1)

aiapatag
aiapatag

Reputation: 3430

Yeah, this is now a feature in .NET Core. Read more from this SO answer. BUT you can hide Lib2 from your MVC csproj using PrivateAssets attribute on your ProjectReference:

in your Lib1.csproj:

<ItemGroup>
    <ProjectReference Include="..\Lib2.csproj" PrivateAssets="All" />
</ItemGroup>

This way, when the MVC.csproj is referencing Lib1, it won't be able to see any Lib2 class because you hid it in your Lib1.csproj.

Upvotes: 1

Related Questions