NuGet Consolidation Report using PowerShell

NuGet Consolidation Report

This post covers a script which allows you to report NuGet package version information over several packages.config files. Given that the tools currently available are slow, I’ve deiced write this script to generate a simple report.

NuGet Consolidation – having packages with different versions

When working with VisualStudio solution files which contains many subprojects, you might eventually end up referencing different package versions. Now, depending on you package strategy or requirements this may not be a problem. You can choose to explicitly include a newer version within one of the projects, however, in general, I would recommend to stick to the same version if whenever possible.

Working with the same version will avoiding modern .dll hell, requiring you to take care of explicit version bindings. It also increases the overall size of the running solution, the time to look up package dependencies and download the packages. For a small project, this doesn’t sound like a big deal but It adds up quickly.

In addition to this, you will need to make sure that your deployment strategies can handle multiple versions of the same assembly. If not you might run into some runtime errors after deployment.

A simple script: list all NuGet packages with a different version

Unfortunately, the current NuGet Consolidation tooling makes is somewhat cumbersome to detect this problem. Because of this, I’ve decided to write a PowerShell script which combines the package information from several packages.config files and filter based on package id and version. I’ve included the full version below and can be called by pointing to the solution directory as shown here:

ListPackagesWithMultipleVersions -sourceFolder 'D:\solutionxyz\'

if you have packages with multiple versions, the result will look something like this:

This includes all required information to resolve the issue. Upgrading or downgrading to any of the desired package versions or remove the reference if unnecessary. The full code is listed below.

Post Navigation