2

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 - Web Project
  • ProjectB - Class Libary Project
  • ProjectC - Tests Project

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 ?

Naren
  • 298
  • 2
  • 10
  • It's behavior of new SDK-style csproj used for .NET Core. But there is an option to can get the old behavior if you want: https://stackoverflow.com/a/60852224/350384 – Mariusz Pawelski Mar 25 '20 at 16:27

1 Answers1

3

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

Roman Svitukha
  • 1,302
  • 1
  • 12
  • 22
  • @RSvitukha - Thanks for your response, I'm aware that this is the case in case of .net core projects. But in case of standard .net framework projects this isn't the case. Is there any way to achieve similar behavior in .net core projects. – Naren Jan 01 '19 at 00:17
  • @NarendraChava added update how to disable transitive reference behavior. – Roman Svitukha Jan 01 '19 at 12:43
  • great! That answers my question. Thanks !! Here’s a link to the same question with better articulation :) https://stackoverflow.com/questions/42428571/transitive-references-in-net-core-1-1 – Naren Jan 01 '19 at 15:47