Use NDepend to Improve your .NET Code Quality

access_time 6 years ago visibility797 comment 0

The first post about NDepend

First of all, I’d like to thank you Patrick (owner of NDepend http://www.ndepend.com) to provide me the professional license of NDepend. This is definitely a cool and powerful tool even I just started using it.

In this post, I am going to introduce the simple steps I used to detect my project’s code quality.

Install NDepend

Go to page http://www.ndepend.com/download and download the trial by simply providing your Email.

Follow the official instructions to install it (http://www.ndepend.com/docs/getting-started-with-ndepend).

Get familiar with the menu

Once installed, the NDEPEND menu will be added into the Visual Studio menu, where you can initiate code analysis. You can also do the same via NDepend Start Page links.

image

image

Starting to analyze

Click the link ‘Analyze VS solutions and VS projects’ to start analyzing.

image

In the dialog, select your solution and then click OK button to continue.

image

In the ‘Analyze a set of .NET assemblies’ dialog, you can resolve any issues highlighted in red before start the analyzing as sometimes some projects cannot be loaded or there are multiple versions can be found. Normally you can Cleanup and Rebuild your solution to fix most of the issues.

Click ‘Analyze XX .NET Assemblies’ button to continue.

image

In the result dashboard, you can find out the summary about your code quality, e.g. Code Rules violated cases, total line of code, comment lines and so forth. You can also create trend reports about these indicators.

I didn’t realize there are so many issues with my code.  I will definitely use the information NDepend provided to fix all of them.Open-mouthed smile

For example, by clicking one of the violated rule, I can get all the details and then fix them accordingly.

image

Some interesting and helpful diagrams

NDepend provides some helpful diagrams as well to help you understand your projects.

Dependency Matrix

ComponentDependenciesMatrix

Dependency Graph

ComponentDependenciesDiagram

Abstractness vs. Instability

AbstractnessVSInstability

Treemap Metric View

VisualNDependView

With all these diagrams, I will immediately know where I am not not architecting or designing well (and there are a lot places to improve apparently Embarrassed smile).

Summary

NDepend helps me to analyze my code and find out all the coding issues very quickly. I am surprised by the enormous set of rules NDepend provides to validate the code quality.  This is absolutely an powerful and great tool to use if you want to improve your code quality and to adopt the preferred coding practices in .NET. I am just a beginner in NDepend’s world but I will definitely utilize it more in future.

I noticed there are some rules which are covered by Visual Studio but not appearing in NDepend’s result but it may be because I missed them, i.e. CA2241 Provide correct arguments to formatting methods. However this won’t really impact anything. I was actually thinking whether it is possible to bring all the Microsoft defined rules into NDepend?

info Last modified by Administrator at 5 days ago copyright This page is subject to Site terms.
Like this article?
Share on

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts

Want to publish your article on Kontext?

Learn more

Kontext Column

Created for everyone to publish data, programming and cloud related articles.
Follow three steps to create your columns.


Learn more arrow_forward

More from Kontext

local_offer sqlite local_offer entity-framework local_offer dotnetcore

visibility 28660
thumb_up 2
access_time 3 years ago

SQLite is a self-contained and embedded SQL database engine. In .NET Core, Entity Framework Core provides APIs to work with SQLite. This page provides sample code to create a SQLite database using package Microsoft.EntityFrameworkCore.Sqlite . Create a .NET Core 2.x console application in ...

local_offer .NET local_offer C# local_offer dotnetcore local_offer Linq

visibility 15
thumb_up 0
access_time 7 days ago

Language-Integrated Query (LINQ) is a set of technologies based on the integration of query capabilities directly into the C# or VB language in .NET. It allows intuitive query against SQL databases, XML, object list, etc.  This article shows how to return a top N records randomly.  The ...

local_offer dotnetcore

visibility 776
thumb_up 0
access_time 4 years ago

Great introduction about JavaScriptServices ( JavaScriptServices GitHub repository ): Microsoft.AspNetCore.SpaTemplates plugs into dotnet new , providing project templates for Angular 2, Aurelia, Knockout, React, and React+Redux applications. dotnet new -l ...