0

Lets take the following classical architecture : (vs 2019 net core 3.1)

  • One project (A) with Interfaces
  • One project (B) with Implementations
  • One project (C) that make the mapping with interfaces and implementations.
  • One WebSite or consoleApp (D) that reference C and A

In the code of D i can use concrete class of B without build problem even if i dont reference the project. The reference of C bring automatically the B.

I found this thread : In Visual Studio, why are all files automatically part of my C# project? apparently it's a new feature and it would make things easier. But none of the solution works for me.

How can i removed this strange behavior ? If want to be forced to use Interfaces and have a build error if i use implementations in D.

When i right click on my project there is two things : "Load direct dependencies of project" and "Load entire dependency tree of project" this appears to be the solution, but it only open my .csproj in edition...

Thanks !

Harkirat singh
  • 599
  • 6
  • 19
Eric Gontier
  • 131
  • 1
  • 5

1 Answers1

1

you need to edit csproj of C project and update :

<PackageReference Include="B" Version="X.X.X" />

by

<PackageReference Include="B" Version="X.X.X">
   <PrivateAssets>all</PrivateAssets>
</PackageReference>

Microsoft reference : https://learn.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files?WT.mc_id=-blog-scottha#controlling-dependency-assets

  • Hi, @Eric Gontier. Does this solution solve your problem? If it is solved, you can click ‘✔’ to accept it as an answer. It is helpful for community members to solve the similar problems. – Hui Liu-MSFT Jun 29 '21 at 06:00