Transitive References in .Net Core 1.1

Transitive references in .Net Core 1.1

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.

Disable transitive project reference in .NET Standard 2

Well my question was close to one marked as duplicate here but to solve it requires different tactic.

Thanks to comment from "Federico Dipuma" and the answer given here I was able to solve this problem.

You should edit the Service.csproj file and add PrivateAssets="All" to ProjectReference keys you don't want to flow to top.

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

Why is .net core allowing assembly access through project dependencies

So, turns out this is by design and the workaround is this:

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

See also this github issue

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

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>

Sample Image

.NET Core transitive Dependency for a .NET 4.6 Project

First, your question is not related to .NET Core at all, as your xproj files do still target net46 and not netstandard1.3 (or lower).

If your only issue is that you can't reference Project C, then you need to package ProjectC into a nuget package, setup a nuget source and add it to your NuGet.Config (http://www.visualstudio.com/en-us/docs/package/nuget/consume).

Or use Visual Studio 2017, which allows you to directly reference a 4.x *.dll inside the csproj (xproj and project.json being deprecated from now on).

ASP.Net Core allows chained project referencing

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.

Showing classes from indirectly referenced packages in .NET Core

I've been struggling with this for months and finally found a way to disable the transitive references of projects in Core.

In the .csproj file for .Facade.EF, you can add PrivateAssets="All" to the ProjectReference to .DAL:

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

With this setting, projects that reference .Facade.EF no longer reference .DAL too.

In more abstract terms, if you want A to reference B and B to reference C, but don't want A to reference C, add this:

In B.csproj

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

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



Related Topics



Leave a reply



Submit