0

I have created a library project that uses several NuGet packages. When I load my library into another project as a reference, the outer project can see and call all the references that my library uses.

MyLib.csproj

    <PackageReference Include="System.Drawing.Common">
      <Version>5.0.3</Version>
    </PackageReference>

Apparently that the project that uses MyLib has access to System.Drawing.Text, for example, as well.

Is there any way to hide public classes of references in MyLib, so the outer project will not be able to see them?

nrofis
  • 8,975
  • 14
  • 58
  • 113
  • 1
    Any reasoning why you want to hide it? – Ralf May 16 '22 at 16:34
  • Yes, I'm using several dependencies like `System.Drawing.Common` some of them are forks of open source projects that we've changed. Some projects that use us as a dependency and use same open source project (officially) has collisions with us (same fully qualified type name) and unexpected behaviors due to our changes in the fork. We don't want that who use us will see our custom made dependencies – nrofis May 16 '22 at 17:31
  • @nrofis How do you have include libraries as NuGet packages but also have change them? How do you add these NuGet packages to your projects? – Progman May 16 '22 at 17:38
  • System.Drawing is fairly notorious, Unix gave it hard time. You didn't make that any easier by forking your own. You'll have to make sure that the library only uses it in its implementation. In other words, none of the public methods and properties of the library should exposes a type from it in their signature. Because then the consumer of the library is forced to add a reference to System.Drawing as well, either simply to use the method/property or because the compiler insists on a reference to resolve an overload. And that's where the trouble starts. – Hans Passant May 16 '22 at 18:34
  • @Progman private NuGet feed. We have forked the source code, changed it, and packed it into our private NuGet feed. – nrofis May 16 '22 at 18:43
  • @HansPassant If I understand you correctly, the reference is public since one of its types appears in some public member in our library? I don't think this is the case but I will double check it – nrofis May 16 '22 at 18:44
  • @nrofis Do you "publish" it with the same version number, which is already used by the upstream repository or do you have a custom separate version number? – Progman May 16 '22 at 19:00
  • @Progman no, we defined a separated version number – nrofis May 16 '22 at 19:03
  • @nrofis You might want to check other questions like https://stackoverflow.com/questions/49307481/supporting-multiple-versions-of-nuget-package-in-one-library-nuget-package – Progman May 16 '22 at 19:08
  • I saw that already. All the solutions there increase complexity for the library users. – nrofis May 16 '22 at 19:38

0 Answers0