How to Setup and Use NDepend on macOS for .NET Development
I am hands-on Software Architect and Tech Lead with over 17 years of experience designing, developing and deploying various commercial software architectures on the full stack.
Search for a command to run...
I am hands-on Software Architect and Tech Lead with over 17 years of experience designing, developing and deploying various commercial software architectures on the full stack.
No comments yet. Be the first to comment.
Most teams make their most critical architectural decisions during the first few weeks of a project. That's also when collective knowledge about the domain is at its absolute lowest. It's the Project
You've decided on Vertical Slice Architecture. Now comes the question that trips up every team: how do you actually organize the folders? I've tried all the common approaches. Some blew up at scale. Others worked fine until someone tried to extract a...
I built this template because I was tired of creating the same boilerplate every time I started a new project. After writing about Vertical Slice Architecture and seeing the pattern gain traction, I w
Project structure shapes everything: onboarding speed, maintainability, how fast you ship features. For years, Clean Architecture (and its cousins Onion and Hexagonal) was the default. But Vertical Sl
Are you a .NET developer working on macOS, striving for high-quality code? If so, NDepend is one tool you should not overlook. In this post, we'll cover everything from setting it up to running your first analysis. Let's get started!
My recent exploration of NDepend, thanks to an invitation from Patrick at NDepend, sparked my interest in its potential to enhance my codebase. As a Software Architect, I often use static code analysis tools to enhance code quality, and NDepend didn't disappoint.
Visit the official NDepend website and download the macOS version. Your download will be a ZIP file containing everything you need.
Unzip the downloaded file to a location of your choice. Let's say we've extracted it to ~/NDepend for this guide. All further CLI commands will work as if you extracted NDepend to this path.
NDepend requires the .NET SDK to run. If you don't have it installed, you can download it from the .NET website. Follow the installation instructions specific to macOS.
This can be done using the dotnet command with the path to your NDepend file.
dotnet ~/Ndepend/net8.0/NDepend.Console.MultiOS.dll --RegEval
After you should see a message like this:
Evaluation registered on this machine
Evaluation 14 days left
Recently, I decided to try NDepend on my VerticalSliceArchitecture project. I was pleasantly surprised by the detailed HTML report I received within seconds. The steps I followed were pretty straightforward.
With NDepend and the .NET SDK installed, you're ready to create your first NDepend project. Here's how to do it:
Fire up your Terminal app. We'll be using the command line to run NDepend.
NDepend uses project files (.ndproj) to know what assemblies to analyze. NDepend.Console.MultiOS.dll can be used to create an NDepend project file (.ndproj extension). I created a project by pointing at my solution file e.g.:
dotnet ~/NDepend/net8.0/NDepend.Console.MultiOS.dll --CreateProject ./VerticalSliceArchitecture.ndproj ~/code/VerticalSliceArchitecture/VerticalSliceArchitecture.sln
If successful, you’ll get a confirmation message and the default NDepend project file will be created for analysis of your solution or project.
Follow these steps to run your analysis and review the results.
From the project directory, I run the following command:
dotnet ~/NDepend/net8.0/NDepend.Console.MultiOS.dll VerticalSliceArchitecture.ndproj
Replace VerticalSliceArchitecture.ndproj with the path to your NDepend project file.
Once the analysis completes, NDepend will generate a nice HTML report in the NDependOut folder. Open the generated /NDependOut/NDependReport.html report in your browser to explore various metrics, code rules, and potential issues found in your codebase. Since my VerticalSliceArchitecture project code broke some rules, the command line exited non-zero. This is great for build integration where I want to fail if rules get violated.
Here’s a quick glimpse of the detailed insights and analysis you can expect from NDepend:

For a deeper look, explore sample reports from other projects to see the breadth of data and actionable recommendations NDepend provides.
I believe there's always room for improvement. Here are a few suggestions that could refine the user experience further.
Incorporating an installation method that aligns with usage of package managers, like Homebrew, or maybe if it is available as dotnet tool would be great. For example executing dotnet tool install ndepend-tool -g sounds quite handy.
Running the cross-platform executable currently requires a somewhat lengthy command:
dotnet ~/path/to/net8.0/NDepend.Console.MultiOS.dll
The command line executable is used for various actions like creating projects, registering licenses, and running analyses. It could be more intuitive if commands followed a hierarchical command structure e.g. <tool> <command> [subcommand] [options].
These suggestions aim to enhance the efficiency and user experience of NDepend, and that usage is intuitive and self-explanatory.
If you are working on Windows and using Visual Studio you will benefit of having graphs and code architecture diagrams like this dependency graph. These graphs are really helpful, and they helped me to improve code architecture of VerticalSliceArchitecture and resolve coupling issues, as noted here on NDepend blog on comparing Clean Architecture and Vertical Slice approach. Here is the example of dependency graph of VerticalSliceArchitecture project:

Luckily, NDepend have plans to add SVG graphs to HTML reports like these:
https://www.ndepend.com/Res/v2020.1/AspNetCore3.1.html
https://www.ndepend.com/Res/v2020.1/DependencyGraph.html
And there you have it! You've successfully set up NDepend on your Mac, analyzed your .NET codebase.
NDepend is a powerful tool in maintaining high-quality code. By regularly analyzing your code, you can catch issues early, adhere to best practices. The tool's analysis capabilities and detailed reports ensure your code remains clean, efficient, well-structured.
While there are opportunities for enhancing the tool's user experience, such as streamlining installation and command structures, availability of graphs in HTML reports, NDepend remains a robust tool in the pursuit of code excellence.
If you're looking for a practical example of setting up and running NDepend, check out my VerticalSliceArchitecture GitHub repository.
I've included:
A complete step-by-step instruction guide for integrating NDepend.
A helper shell run-ndepend.sh script to streamline the process.
This example demonstrates how NDepend can be used effectively to analyze and enhance a real-world project.