Integrate NDepend 2020 into your .NET Core projects
Introduction
In computer science and software engineering in particular, software quality is an overall assessment of software, based on numerous indicators.
Comprehensiveness of functionality, correctness and accuracy of results, reliability, fault tolerance, ease and flexibility of use, simplicity, extensibility, compatibility and portability, ease of correction and transformation, performance, consistency and integrity of the information it contains are all quality factors.
In software engineering, factoring data and code is the universal way to get quality.
We will talk in this article about NDepend, a tool to help software developers achieve a high level of quality in their programs.
What’s NDepend?
NDepend was created by Patrick Smacchia in 2004, this tool was marketed in 2007 and has evolved a lot since, it offers code analysis for your .NET and .NET Core applications and you can try it free for 14 days. It can be used in standalone or integrated Visual Studio mode.
NDepend gives you one-click access to many metrics in your code with a graphical representation. Interesting!
With the dashboard, the most interesting feature of NDepend is the query language on which it is built: CQLINQ
But before we briefly look at the installation process.
Installation
Installing the NDepend extension for Visual Studio is really easy, download it at this address https://www.ndepend.com/download and install it like this by clicking on Visual Studio Extension Installer, then select the version of Visual Studio on which you install:
The great thing about NDepend is the ease with which you can get started and the great documentation available on their website. There are online videos, tutorials, screenshots, step-by-step explanations and you can’t go wrong.
For more details, you can go here for: https://www.ndepend.com/docs/getting-started-with-ndepend#Tuto
Executing NDepend
You can run NDepend in standalone mode with the VisualNDepend.exe executable (in the same installation directory as the Visual Studio extension executable) or run the extension in Visual Studio from the menu:
1- Dashboard
On the same dashboard screen, NDepend provides numerous metrics such as:
- Technical debt
- Lines of code
- Comments
- The different levels of problems in the code
- Programming rules
- Code coverage
- The quality gates
And many other features! Each metric can be clicked for further details.
It provides a really huge analysis of your code, you can at any time take a look at a small summary and recalculate your dashboard by clicking on the colored circle at the bottom right of your screen, very practical !
2- CQLinq
CQLinq, which stands for Query Code Linq, allows you to write C # Linq queries on an abstract model of your code. Concretely, you can query your code in the same way as you would query the views or tables in a database. For example, to find all of the class constructors, I wrote the following query:
from m in Methods where m.IsConstructor select m
If you want to write your request, go to the NDepend menu, select “Rules” and “View Editor Panel”:
It opens a small window where you can type your request, at the same time, the result is displayed at the bottom, nice isn’t it ?
3- Dependency graph
Thanks to NDepend exploring the existing code architecture in Visual Studio via the dependency graph is done in a few clicks, go to the NDepend menu, select “Graph” and “View Dependency graph”:
By default, the NDepend dependency graph panel displays the dependency graph between .NET assemblies :
Many possibilities are offered to generate all kinds of graphs such as call graphs, coupling graph between two components, graphs of monolithic code portions.
Conclusion
I did not present all the features of NDepend because it is a very large and complete product, I chose the most interesting features in my opinion.
I did not specify that all the NDepend results can be differentiated from a baseline: https://www.ndepend.com/docs/code-diff-in-visual-studio
I have not explored the capabilities of technical debt:
- In addition to the dependency graph NDepend also offers a DSM (Dependency Structure Matrix https://www.ndepend.com/docs/dependency-structure-matrix-dsm) and facilities to generate CQLinq queries relating to dependencies (https : //www.ndepend.com/docs/cqlinq-features#Dependencies)
- Visualization of code metrics with a colored Treemap: https://www.ndepend.com/docs/treemap-visualization-of-code-metrics#Color
- In addition to the developer version with integration into Visual Studio, NDepend can be generated in your build process to generate reports https://www.ndepend.com/sample-reports/, this is the Build-Machine version. A third version offers deep integration into Azure DevOps: https://www.ndepend.com/docs/azure-devops-tfs-vsts-integration-ndepend
I honestly think NDepend is very powerful and very easy to use. The CQLinq language and the NDepend dashboard are in fact the best features of the tool and in addition I found nothing equivalent at this level.
However, because NDepend does not fix the code for you, I suggest continuing to use Resharper which can work in synergy with NDepend. There is little overlap between the NDepend and Resharper rule sets, while Resharper focuses more on the details inside the method body, NDepend focuses more on the code structure and overall quality.
The NDepend team is very active and we can expect a lot of good developments in future versions.