Naren
Naren

Reputation: 308

Project reference is enabling me to use code from other dependent projects without explicit project reference

Here's the problem I'm facing, which I think only happens when using .net core and visual studio 2017

I have 3 projects in my solution.

ProjectA has a project reference to ProjectB and ProjectC has a project reference to ProjectA

Since ProjectC doesn't have explicit project reference to ProjectB, I shouldn't be able to refer to ProjectB's code in ProjectC. If I try to use any code from ProjectB in ProjectC I used to get compilation errors. But this is not the case anymore. My solution compiles successfully without any errors. Am I missing anything here ?

Upvotes: 2

Views: 760

Answers (1)

Roman Svitukha
Roman Svitukha

Reputation: 1402

If you reference a project that has references to another project, those references will be automatically added. In your case when you have Project A with a reference to Project B, when you reference project A in project C reference to Project B will be automatically added.

If you would like to disable transitive reference behavior you can add PrivateAssets="All" to your reference in the ProjectA.csproj (WebProject)

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

enter image description here

Upvotes: 3

Related Questions