Saturday, May 24, 2014

Managing NuGet packages dependencies with the Package Visualizer tool

If you ever used NuGet on a large enough solution you know you can get into trouble when projects reference different versions of the same NuGet package. That happens a lot in Azure projects as the libraries/packages get updated all the time.

I'm really surprise when I talk to people using NuGet everyday that they don't know about the Package Visualizer tool. (update: I've been told that this feature requires VS Ultimate and is not available in the Pro version. I'm still going to show it to you but stay tune for another post with a free alternative later)

NuGet Package Visualizer in Visual Studio


Once you open up a solution in Visual Studio you can go to the Tools menu, NuGet Package Manager and Package Visualizer.


This will analyse all the packages.config files in the solution and generate a DGML diagram of all NuGet packages and projects of the solution.  The diagram will help us see packages usage in the solution and find the ones with different versions.  Below you can see that I've tried this on the Roslyn (open source C# compiler) solution.


The first thing to note (and a surprise to me!) is that Roslyn use the XUnit testing framework and not MsUnit! More seriously we can quickly see that we have no duplicate packages with different versions. If we compare that to this sample solution I created we can see I'm using two versions of the Json.NET library. Now I know I should update the ClassLibrary1 project to use the new version of the package.


Of course, this only work for NuGet packages but it would be useful to have something like this for regular DLL references.  I'll try to work on a LinqPad query to generate such a DGML graph with all projects, libraries and packages.  Stay tune till next time.

2 comments:

TormodH said...

Thank you for sharing this! I have been looking for this tool for ages, without success. I recently stumbled upon it, however, and spent 30 minutes figuring out how I opened it (by mistake) initially. I figured out that you must have the "solution item" in your solution explorer selected to see this tool in the menu. Great tool, thanks! Running VS Professional 2013.

TormodH said...

Edit: In order to use this tool, you actually have to open it right after a fresh restart of Visual Studio; that is: 1. Restart Visual Studio 2. Go to Tools -> NuGet Package Manager -> Package Visualizer. If you do not restart the editor before looking for this tool, it won't be there... Seems like a bug to me. Maybe the devs at Microsoft couldn't limit the tool to the Ultimate version after all. :))