Search code examples
c#.netnugetnuget-packagemorelinq

How to avoid ambiguous references on nuget source code packages includeded in two projects with internalsvisibleto


Let's say you have two projects:

  • Main.csproj
  • Main.Test.csproj

And Main has an attribute

[assembly:InternalsVisibleTo("Main.Test")]

Now we want to reference a NuGet package that ships its content as source code such as MoreLinq (https://code.google.com/p/morelinq/) in both projects.

The problem is that there are now two copies of the source visible to the Main.Test project and therefore the compiler spews an Ambiguous reference error.

Is there any way to avoid this without modifying the source code that the package drops into each project?

P.S. Please don't use arguments such as 'don't use InternalsVisibleTo because...'. I can read those points elsewhere.


Solution

  • The extension methods from morelinq will be public so if you have them in main.csproj, you won't need them in main.test.csproj but they'll still be accessible within main.test.csproj.