1
votes

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 ?

1
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: stackoverflow.com/a/60852224/350384Mariusz Pawelski

1 Answers

2
votes

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