This question pertains to .NET 5+, not .NET Framework.
Consider the following dependency tree:
MyWebsitehas package references toRandomWebLibrary1.0.0 andRandomJsonLibrary2.0.0.- The NuGet package
RandomWebLibrary1.0.0 has a package reference toRandomJsonLibrary1.0.0. - The NuGet package
RandomJsonLibraryhas no dependencies.
My questions:
- What version(s) of
RandomJsonLibrarywill be loaded at runtime? - What happens if
RandomJsonLibrary2.0.0 has a completely different API thanRandomJsonLibrary1.0.0? - Can the author of
MyWebsitedo anything to fix problems that arise from having multiple versions ofRandomJsonLibraryin the dependency tree? Is there an equivalent of .NET Framework's binding redirects in .NET 5+?
I'm asking out of curiosity, not because I am encountering a problem. For reference, here is the documentation on Understanding AssemblyLoadContext which seems relevant but did not answer my question.
These questions are answered by the documentation page How NuGet resolves package dependencies. The "Dependency resolution with PackageReference" section is what's relevant to this question since we are talking .NET 5+.
To answer the original questions:
RandomJsonLibrary2.0.0 will be loaded at runtime.RandomWebLibrarywill throw exceptions at runtime ifRandomJsonLibrary1.0.0 and 2.0.0 have incompatible APIs.MyWebsitecan choose the exact version of any dependent package by installing that package directly intoMyWebsite. In the case ofRandomJsonLibrary, the author ofMyWebsiteshould probably downgrade toRandomJsonLibrary1.0.0 to preventRandomWebLibraryfrom breaking. AFAIK there are no binding redirects in .NET 5+.