Today I am going to be doing a tool spotlight on NDepend. NDepend has a ton of features to help you keep a handle on your applications including the following plus much more.
- Code Rules
- 200 default rules with ability to add custom rules using LINQ
- Quality Gates
- Visual Studio Integration
- Build Process Integration
- Dependency Graph
- Dependency Matrix
- Technical Debit Estimation
For full disclosure, NDepend reached out to me to give their tool a try. I am writing based on my experiences with their tool and will be including both the positive and negative aspects of my experience. None of the links in this post are referrals that would in any way provide me any sort of payment.
Installation
The download is a zip file that you then have to find out what you want to do with. This was the first negative I hit with the product. While it isn’t hard to figure out it would be much nicer if this were an installer where I could select what I wanted to install instead of having to look at the getting started docs right away. For non-build usage, the options to run the tool is either via a Visual Studio extension (NDepend.VisualStudioExtension.Installer) or as a stand alone application (VisualNDepend.exe).
I chose to go explore with the Visual Studio extension. As a hint that I didn’t notice until later, VisualNDepend provides an option to install the Visual Studio extension in addition to providing all the functionality of the Visual Studio extension.
Visual Studio Extention
After installing the NDepend extension there will be a new top level NDepend menu in Visual Studio.
With the solution you want to analyze already open select the NDepend > Attach New NDepend Project to Current VS Solution.
This will launch a dialog that allows you to select which assemblies you would like to analyze preloaded with the assemblies for the current application.
As you can see from the dialog there are a lot of options. If your project has other assemblies or solutions that you would like to be included as part of the analyses they are easy to add. When finished adding items to analyze click the Analyze button at the bottom. I am using a small project for this entry and the process took less than 10 seconds. I also tried it on a large project (500k+ lines of code) and it took less than 30 seconds.
After the analyses are complete the extension shows a dialog asking what to do next as well as launching a web page with the results of the analyses if you kept the Build Report check box checked. Following are the options in the dialog.
From here I chose to View NDepend Dashboard, but also make sure and check out the report that the analyses generated as it provides a great summary at the end of all the issues found. The following is a part of the dashboard.
There is a ton of data provided. If you notice at the top there is a Choose Baseline option which would allow comparisons of solutions over time. I can see this view of a project over time is very helpful, but not a feature I will get to explore here.
Exploration
Exploration of the data NDepend provides is something I could spend hours looking at even on a small project. For example, the following is an output to HTML (their output is much prettier than the version that is shown here) of the issues that make up the critical group in the Rules box in the dashboard above.
4 rules |
Issues |
Debt |
Annual Interest |
Breaking Point |
Category |
Full Name |
Avoid methods with too many parameters |
1 issue |
1h 9min |
5min |
4 522d |
Project Rules \ Code Smells |
Rule |
Avoid non-readonly static fields |
12 issues |
32min |
4h 0min |
48d |
Project Rules \ Immutability |
Rule |
Avoid namespaces mutually dependent |
2 issues |
30min |
1h 1min |
179d |
Project Rules \ Architecture |
Rule |
Avoid having different types with same name |
3 issues |
30min |
1h 0min |
182d |
Project Rules \ Naming Conventions |
Rule |
Sum: |
18 |
2h 41min |
6h 6min |
4 933d |
– |
|
Average: |
4.5 |
40min |
1h 31min |
1 233d |
– |
|
Minimum: |
1 |
30min |
5min |
48d |
– |
|
Maximum: |
12 |
1h 9min |
4h 0min |
4 522d |
– |
|
Standard deviation: |
4.39 |
16min |
1h 28min |
1 899d |
– |
|
Variance: |
19.25 |
34d |
979d |
overflow |
– |
|
Here is the same view inside the Queries and Rules Edit window.
Double click any line will take you to a detail view showing a listing of the rule broken down by project, namespace, and class.
The same window also shows the query that was used to find the rule violations. For example, the above is powered by the following query.
warnif count > 0
from f in Application.Fields
where f.IsStatic &&
!f.IsEnumValue &&
!f.IsGeneratedByCompiler &&
!f.IsLiteral &&
!f.IsInitOnly
let methodAssigningField = f.MethodsAssigningMe
select new {
f,
methodAssigningField,
Debt = (2+8*methodAssigningField.Count()).ToMinutes().ToDebt(),
Severity = Severity.High
}
The above is CQLinq or Code Query LINQ which is used to query the code model that the NDepend analysis creates. The detail of CQLinq are outside the scope of this post, but based on the above you can see how powerfully this could be.
Other considerations
Based on my usage to get the best value from NDepend your whole team would need to be licensed and making sure new code satisfies with all the rules your team wishes to follow. NDepend has a component that can be used as part of server based build processes which is needed, but I would want to use that component as a fail safe, not as a way to avoid buying licenses. If you use multiple computers it seems that you will need multiple licenses which will cause issues for some users.
Wrapping up
After trying NDepend out for awhile I am still amazed at the amount of data it provides. Not to mention the ability to add new queries and rules of your own. One blog post is never going to be enough to cover even a fraction of what this tool does. It feels like Resharper in it does so much that it takes a lot of time to learn and take advantage of the full set of features it provides.