dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.65k stars 1.06k forks source link

Testing ns2.0 libraries, ambiguous reference issues #30151

Open NinoFloris opened 1 year ago

NinoFloris commented 1 year ago

I'm trying to get tests running against a codebase for a library that has two targets: ns2.0 and net7.0. They have significantly diverging codepaths so it would be nice to have both under test. The test project has to be an actual concrete TFM so I've chosen net6.0 and net7.0 for the two library tfms respectively.

The problem starts from this point on. The library project has an IVT for tests but it also defines polyfills for things like System.Diagnostics.CodeAnalysis attributes, and at this point ambiguous references appear in the test project for the net6.0 tfm. This tfm references the ns2.0 library which defines the polyfills while also having a reference to System.Runtime/System.Private.CoreLib defining the same types.

What should I do here? Should I stop trying to test this project against its ns2.0 target? Or should I somehow be able to add an extern alias for System.Private.CoreLib, (not super desirable but it could be ok) and if so, how?

The latter question is the reason I've opened the issue here and not some other place.

EDIT: I have another shitty solution, segregate all the polyfills to another project which is only IVT to the library and not the tests...

nohwnd commented 1 year ago

Getting a simple repro project would help me immensely to investigate, would you be able to provide it please?

NinoFloris commented 1 year ago

Apologies, I have missed this comment entirely. Maybe the context in the linked (I'm one of the maintainers) Npgsql issue helps enough. If not I'll whip up a repro!