Transitive references in .Net Core 1.1

You have two options.

  1. In ClassLibrary1.csproj use DisableTransitiveProjectReferences property

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>netcoreapp3.1</TargetFramework>
            <DisableTransitiveProjectReferences>true</DisableTransitiveProjectReferences>
        </PropertyGroup>
        <ItemGroup>
            <ProjectReference Include="..\ClassLibraryCore2\ClassLibraryCore2.csproj" />
        </ItemGroup>
    </Project>
    
  2. In ClassLibrary2.csproj use PrivateAssets="All"

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>netcoreapp3.1</TargetFramework>
        </PropertyGroup>
        <ItemGroup>
            <ProjectReference Include="..\ClassLibraryCore3\ClassLibraryCore3.csproj" 
                PrivateAssets="All" />
        </ItemGroup>
    </Project>
    

I explained the difference more in other answer.


Transitive project-to-project references are a new feature of Visual Studio 2017 and Microsoft.NET.Sdk. This is intentional behavior.

See https://github.com/dotnet/sdk/issues/200.


If you're interested in disabling the transitive reference behavior, I finally found a way.

If you want Project A to reference B and B to reference C, but don't want A to reference C, you can add PrivateAssets="All" to B's ProjectReference to C, like so:

In B.csproj

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

This setting makes C's reference private so it only exists within B. Now projects that reference B will no longer also reference C.

Source: https://github.com/dotnet/project-system/issues/2313