Home > Blockchain >  Different versions of same DLL in Multiple nuget package in Same .Net 6 Project
Different versions of same DLL in Multiple nuget package in Same .Net 6 Project

Time:04-14

I have one base nuget library called Foundation.dll. I have another 5 nuget libraries which are using a different version of Foundation.dll. Everything is in one project.

  1. My question is when I build a project, VS .Net is obviously going to put only one Foundation.dll in the bin/debug folder. So how VS/.Net decides which nuget package's foundation.dll should be put in the bin/debug folder. Is it randomly?

  2. If I do reference Foundation.dll directly in the project then it is putting my direct reference version into the bin/debug folder but for some other developers in the team, it is putting an older version.

it is very scary that the same exact branch code in 2 different machines works differently. I added one argument in one of Foundation.dll's methods & for one developer it is working but for another developer, the same exact code gives a compilation error.

What is the ultimate solution to this problem? What change should I make in my project?

Thank you.

CodePudding user response:

This is a difficult topic and yes, there are a lot of factors that determine which version is being put to the bin folder. Normally, the compiler chooses the latest version from all the dependencies automatically. But particularly if you have several "final" assemblies in your solution (e.g exe's, unit test libraries) the compiler sometimes gets it wrong. Usually, the code works anyway, but I agree, this is scary.

The actual outcome may depend on the build order, build environment (whether building from the command line or within VS, etc.). Me and my team has had a hard time figuring out the best way around this problem.

The safest approach we found is to reference the latest version of your package directly in the project. This does not need to be the latest version available, but the latest version used anywhere within your solution. Of course, this only works if the versions are backwards compatible. If some library requires an older version of the dependency and you can't rebuild that library, you are in for really big trouble.

CodePudding user response:

I've met the same issue. One project in the solution was depending on .net standard version of a library, while others were expecting a classic framework version.

As PMF wrote, which library will finally occur in the output depends on a build order.

I've solved it by copying the .net standard version into the output folder on post-build events.

  • Related