4

Consider this setup in .net framework projects/assemblies:

  • layer3 (.net framework console app) references Layer2
  • Layer2 (.net framework library) references Layer1
  • Layer1 (.net framework library) references nothing

Now when I try to access Layer1 from Layer3, it won't allow me:

enter image description here

The type or namespace name 'Layer1' could not be found (are you missing a using directive or an assembly reference?)

This makes sense.

Now when I create the same setup in .net standard projects and a .net core console app, like so:

  • layer3 (.net core console app) references Layer2
  • Layer2 (.net standard library) references Layer1
  • Layer1 (.net standard library) references nothing

I am able to to this, and compile just fine:

enter image description here

Which makes no sense to me.

Is this by design? How do I prevent this behaviour?

Flores
  • 8,226
  • 5
  • 49
  • 81

1 Answers1

3

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

Flores
  • 8,226
  • 5
  • 49
  • 81