Untangle and Understand DLL Dependencies with NDepend

If you do any development beyond the most basic on the .Net Framework, understanding and resolving DLL dependencies is a necessity and a fact of life and without the right tools to guide you, this can be a very time consuming and frustrating exercise. One only needs to look on Stack Overflow/ Google on this issue and see the number of developers seeking help with this. Unfortunately, not all solutions out there work or give you the complete picture the way it should in a quick and easy manner.

One of the better ones on the market that does this and more is NDepend.NDepend is actually a Visual Studio static analyzer that helps you analyse, understand, manage and write better code-explaining/resolving DLL dependencies is just one of the many things it helps you with, it does much more including automating code reviews in highly effective visual manner. Rather than repeat everything it does or how it does it all, as all that and more can be found on the official site as well as the many blogs out there, I’ll give a quick demo on how I used some of my favorite features of NDepend for one of my upcoming project/blogs

But to be clear and as many others have stated previously, this tool can get fairly complicated very quickly: you really need to be building some serious software to really get the most out of it, many of the features here would be an overkill for your beginner developers. Having said that, NDepend is useful for all developers (.Net), and not just those writing solutions with million plus lines of code like some of NDepend’s larger clients- I encourage everyone to give it a spin and see for themselves-getting started is actually much, much easier than it looks. You’ll truly begin to understand your code base once you begin using this.

And because so much has been written about it, it’s also probably worth repeating- while NDepend helps with refactoring, it  is not ReSharper (or Code Map for that matter). The three compliments and does not replace each other. And just like ReSharper, I think this is probably going to be one of those tool I can’t work without…

Give it a go…

DLL dependencies can pop up anywhere -I’m encountering it here on some recent work for a CLR stored proc that scrapes data off a web page
NDepend with HtmlAgilityPack
Knowing the dependencies of third party DLLs is absolutely critical for any development/deployment. HtmlAgilityPack is a popular web scraping library (DLL) and with the help of NDepend, I immediately know what other DLLs are needed by SQL Server for my project. It even reminds you where these are located (circled).
NDepend Namespace
NDepend showing the Namespace dependencies/relationship for my simple CLR proc, at the beginning anyway
NDepend relationship
But many dependencies are not as simple and can get pretty complicated as this graph above shows. You really need to use this to see the sophistication of this tool-this is live and interactive.
Dependency Matrix in NDepend
The Dependency Matrix provides another way of looking at your dependencies but the entire grid is interactive with context menus to perform various tasks.  While the graph is probably more intuitive,  it is suggested to use the matrix when the dependency graph becomes too large or unreadable.
SQLing NDepend
There’s even an API that allows you to develop your own static analysis tool using CQLinq (Code Query LINQ). I’m testing this function/query here via the friendly GUI
Analyziing folders in NDepend
One of my favourite features, the ability to just analyse a folder of DLLs without ever having to open Visual Studio. I love and work with Linqpad a lot-for me, just export DLLs from Linqpad to a temporary folder and analyse from there. Here, I’m looking at the libraries for Azure’s NoSQL database, DocumentDB (now called Cosmos)
Automated Code Reviews in NDepend
Automated Code Reviews via LINQ. This is simply awesome and being visual makes things so much more easier and objective.  There’s over two hundred rules built in- you can of course expand and or modify any of these. This is for the rule ‘Avoid methods too big, too complex -glad I’m not the only one 🙂 
Another Rule-NDepend
Because I like this so much, here the rule “Potentially Dead Methods”

Leave a Reply