How to hide types of a NuGet package

  Kiến thức lập trình

I developed a .NET 8 NuGet package “A”, which uses a 3rd party NuGet packages “B”, in turn uses the Json.Net(Newtonsoft.Json) package.

"A" -> "B" -> "JSON.NET"

Since NuGet packages are “transitive”, so all package A’s consumers would have access to Json.Net, but this is kind of a pollution because they use System.Text.Json as the JSON library.

"Consumer" -> "A" -> "B" -> "JSON.NET"

So my question is, is there a way to hide or stop exposing types of a NuGet package, in my case, I want to hide types of Json.NET exposing by package B.

And because I can’t change B’s source, so I can’t modify it to use PrivateAssets="all".