Let’s have fun with another tool in the .NET-universe: NDepend. NDepend is a high-level code / IL analysis tool. In this post I give a short overview. In future posts I will dig into some details and useful stuff you can do with it.
Download NDepend from this website here. There’s a free trial version which you can use to play around. NDepend runs as standalone tool, but also can be integrated into Visual Studio.
For this blog post I use the source of one of mine favorite open source .NET libraries, Autofac .
The name of the tool already tells you that NDepend can do dependency analysis, and it can do it really well. It can analyze the dependencies between assemblies and Visual Studio projects. The visual representation looks something like this:
When you hover on an assembly on the graph or on the list, NDepend highlights all dependencies. For example when you hover over the ‘Autofac’-assembly, you can see what dependency it has and which other assemblies depend on it. An alternative view for dependencies is the dependency matrix. Again, the popups of NDepend explain what the numbers mean.
Of course you cannot only do such dependency analysis on assemblies level, but one other level. From the assembly level, over namespaces and classes down to the single methods. Like here for Autofac.
One of the coolest feature of NDepend hasnothing to do with dependency analysis, but rather code analysis. It’s the ‘Code Query Language’. This is a SQL dialect which allows you to write queries against the code. Now you wonder what this is useful for? Well mostly for defining your own code-metrics, find code-smells or find out certain properties of your code. NDepend brings already a rich collection of predefined queries with it, ranging from code quality metrics to API usage statistics. All queries can be set up to be a warning when a certain threshold is exceeded. This makes NDepend a nice code quality analysis tool.
Analyze Over Time
NDepend can analyze two different versions of the same project and then compare the changes. For example NDepend can find out if you have breaking API-changes in a newer version etc.
Another feature of NDepend is to create nice reports about a project. Those reports contain give an overview over dependencies, statistics etc. I think these reports are a great way to monitor a project. For example you could integrate them into your continues build and monitor if certain metrics are getting better or worse. Take a look at an example report of db4o here.
Conclusion And Follow-Up
To sum things up, NDepend is a powerful tool for dependency and code analysis. Play with it yourself with the trial version.
In the next blog post I’m going to play around with the Code Query Language and show a few use cases for it. Stay tuned.
- Single App-Instance in .NET
- Wolf Lake