NDepend

NDepend is a static analysis tool for .NET managed code. The tool proposes a large number features, from dependency visualization to Quality Gates and Smart Technical Debt Estimation. For that reasons the community refers to it as the "Swiss Army Knife" for .NET Developers.

Features

The main features of NDepend are:

 Dependency Visualization (using dependency graphs, and dependency matrix)
 Smart Technical Debt Estimation
 Quality Gates
 Declarative code rule over C# LINQ query (CQLinq). The NDepend default Rules-Set has few overlap with popular Roslyn analyzers. Roslyn analyzers are good at analyzing the code flow - what is happening inside a method - while the NDepend code model, on which the NDepend rules are based, is optimized for a 360 view of particular higher-scale areas including OOP, dependencies, metrics, breaking changes, mutability, naming...
 Software metrics (NDepend currently supports 82 code metrics: Cyclomatic complexity; Afferent and Efferent Coupling; Relational Cohesion; Google page rank of .NET types; Percentage of code covered by tests, etc.)
 Code Coverage data import from Visual Studio coverage, dotCover, OpenCover, NCover, NCrunch.
 Version comparison of two versions of the same assembly
 Integration with Visual Studio 2022, 2019, 2017, 2015, 2013, 2012, 2010, or can run as a standalone through VisualNDepend.exe, side by side with Jetbrains Rider or Visual Studio Code.
 Reporting and CI/CD Integration with Azure DevOps, Bamboo, Jenkins, TeamCity, AppVeyor

Code rules through LINQ queries (CQLinq)

Live code queries and code rules through LINQ queries is the backbone of NDepend, all features use it extensively. Here are some sample code queries:

 Base class should not use derivatives:

 // <Name>Base class should not use derivatives</Name>
 warnif count > 0 
 from baseClass in JustMyCodeTypes
 where baseClass.IsClass && baseClass.NbChildren > 0 // <-- for optimization!
 let derivedClassesUsed = baseClass.DerivedTypes.UsedBy(baseClass)
 where derivedClassesUsed.Count() > 0
 select new { baseClass, derivedClassesUsed }

 Avoid making complex methods even more complex (source code cyclomatic complexity):

 // <Name>Avoid making complex methods even more complex (source code cyclomatic complexity)</Name>
 warnif count > 0 
 from m in JustMyCodeMethods where
  !m.IsAbstract &&
   m.IsPresentInBothBuilds() &&
   m.CodeWasChanged()
 let oldCC = m.OlderVersion().CyclomaticComplexity
 where oldCC > 6 && m.CyclomaticComplexity > oldCC 
 select new { m,
     oldCC, 
     newCC = m.CyclomaticComplexity, 
     oldLoc = m.OlderVersion().NbLinesOfCode,
     newLoc = m.NbLinesOfCode,
 }

Additionally, the tool provides a live CQLinq query editor with code completion and embedded documentation.

See also
 Design Structure Matrix
 List of tools for static code analysis
 Software visualization
 Sourcetrail

External links

NDepend reviewed by the .NET community
Exiting The Zone Of Pain: Static Analysis with NDepend.aspx (Program Manager, Microsoft) discusses NDepend
Stack Overflow discussion: use of NDepend
Abhishek Sur, on NDepend
NDepend code metrics by Andre Loker
Static analysis with NDepend by Henry Cordes
Hendry Luk discusses Continuous software quality with NDepend
Jim Holmes (Author of the book "Windows Developer Power Tools"), on NDepend.
Mário Romano discusses Metrics and Dependency Matrix with NDepend
Nates Stuff review
Scott Mitchell (MSDN Magazine), Code Exploration using NDepend
Travis Illig on NDepend

Books that mention NDepend
 Girish Suryanarayana, Ganesh Samarthyam, and Tushar Sharma. Refactoring for Software Design Smells: Managing Technical Debt (2014)
 Marcin Kawalerowicz and Craig Berntson. Continuous Integration in .NET (2010)
 James Avery and Jim Holmes. Windows developer power tools (2006)
 Patrick Cauldwell and Scott Hanselman. Code Leader: Using People, Tools, and Processes to Build Successful Software (2008)
 Yogesh Shetty and Samir Jayaswal.  Practical .NET for financial markets (2006)
 Paul Duvall. Continuous Integration (2007)
 Rick Leinecker and Vanessa L. Williams. Visual Studio 2008 All-In-One Desk Reference For Dummies (2008)
 Patrick Smacchia. Practical .Net 2 and C# 2: Harness the Platform, the Language, the Framework (2006)

Static program analysis tools
.NET programming tools
Software metrics