Ivan
Ivan

Reputation: 9665

Disallow to use multiple versions of NuGet packages in solution

We have a complex Visual Studio solution with projects referencing the same NuGet packages of different versions.

I feel this is a bad practice, as potentially can lead to dll hell

So - is there a way to control this?

Ideally it should be a part of either:

I really liked Package Manager Console Powershell Reference. But I couldn't find a way to use those cmdlets (Get-Package and Get-Project -All) in external Powershell script outside of VS.

The simplest solution I see is to write a custom Powershell script, which reads .sln file, gets all the projects and for each of them reads packages.config and takes all nuget packages versions from there.

Or ... use a VS DTE to simplify this job, but so far I didn't have an experience of using it.

And then ... once we have this script - we can run it in CI.

Is there a simpler \ more standard way of doing this?

Upvotes: 2

Views: 815

Answers (2)

Mike Beeler
Mike Beeler

Reputation: 4101

At least as far as nuget is concerned, nuget can install different versions of packages in different projects. That said it's not advisable. As to which packages get restored it looks at the packages file (XML) anything in the file will get restored.

This file can get out of sync depending on how the package references were removed from the project/solution.

Upvotes: 1

demoncodemonkey
demoncodemonkey

Reputation: 11957

You should not worry about multiple components referencing different versions of packages. NuGet was built to cater for this scenario.

With DLL hell, you had no idea if A.DLL could work with a new version of B.DLL. But with NuGet the dependency is specified explicitly with a range of compatible version numbers.

The version resolution used by NuGet is to always pick the lowest version of a dependency that fits in the range.

Read here for details, it explains it well:

http://blog.davidebbo.com/2011/01/nuget-versioning-part-2-core-algorithm.html

Upvotes: 1

Related Questions