n today’s article, we will look into an extremely useful tool that integrates into our Visual Studio environment. This tool is called NDepend, and it gives us valuable insights into our application in terms of code analysis, dependency graphs to visualize the flow of our application, code differences using a baseline, build process health to name a few.
How to get NDepend?
We can browse to the NDepend site at the below URL, https://www.ndepend.com/
From here we can download the 14-day trial version.
Once you have downloaded the zip file, you can install the tool for your desired version of Visual Studio. I installed the version for Visual Studio 2019, to run it with my installation of Visual Studio 2019 Community Edition.
Once the installation is complete, we are ready to test the tool.
I have created a new .Net Core 3.1 MVC project called “WebApplicationCore” inside a solution named “WebApplicationCoreSol” using the default template as below,
Next, we verify it runs correctly,
Next, we will see how to use NDepend to analyze this project’s code. Select “Extensions”, “NDepend” and then “Attach New NDepend Project to Current VS Solution” as below,
Then click the “Analyze 2 .NET Assemblies” button.
When the processing is complete, we see the below screen,
From here, click the “View NDepend Dashboard” option. We will then see the below,
A report will also open in the browser as below,
Clicking on the “Dependency Graph” will show the dependencies of the application and how they relate to each other. This is extremely useful for large solutions with multiple projects and complex dependencies.
Coming back to the Dashboard in Visual Studio we can see the baseline is the same as the current code, as this was our first run.
Later, we can specify a different baseline for comparisons.
Let us look at the Rules. Click on the Ok rules number as below,
And you will see a list of rules that the code has been analyzed against. We can also write our own code rules. To see further details of the rules, simply hover over a rule in the bottom right window as below,
We have looked at two out of the numerous features in this tool. I would recommend you download the tool and look through the documentation to see the different options and reports available.
There is just one more thing I would like to mention today. We can also run the tool from outside of Visual Studio.
Simply open the zip file folder as below,
Run the “VisualNDepend” application and you will see the below,
From here you can start a new NDepend project or simply open the one we created earlier on our MVC solution,
In this article, we looked at a useful tool called NDepend. This tool helps us with code analysis to determine if our code meets certain standards. We also saw the dependency diagram to help us understand the relationship between entities. These are two of the simplest features of this tool. Once you download and go through the documentation you will find many other helpful features which can make your coding and coding process much more efficient. Happy coding!
The Tech Platform