C# Dependency Graph: Complete Guide

Master dependency visualization for .NET and C# projects. Learn to use Visual Studio, JetBrains Rider, NDepend, and open-source tools to understand project relationships, detect circular dependencies, and analyze coupling in your solutions.

What is a C# Dependency Graph?

A C# dependency graph (or project dependency diagram) visualizes how projects in a Visual Studio solution depend on each other. Each node represents a project (assembly), and arrows show which projects reference which.

Unlike code-level dependency graphs, C# dependency graphs operate at the project/assembly level, showing:

Why Visualize C# Dependencies?

Understand Large Solutions

Solutions with 50+ projects become impossible to navigate mentally. A visual graph shows architecture at a glance.

Detect Circular Dependencies

When Project A → B → C → A, nothing can compile. Dependency graphs spot these immediately.

Refactor Safely

Before moving code or deleting a project, see what depends on it and what might break.

Identify Coupling Issues

Tight coupling between projects signals architectural problems. Visualize coupling to prioritize refactoring.

Onboard Developers

New team members understand the codebase structure in minutes instead of weeks.

Plan Microservices

When splitting a monolith, dependency graphs show natural boundaries for services.

C# Dependency Graph Example

Simple C# Solution Structure: MyApp.sln ├── MyApp.Core (no dependencies) ├── MyApp.Data → MyApp.Core ├── MyApp.Services → MyApp.Core, MyApp.Data ├── MyApp.API → MyApp.Services ├── MyApp.Tests → MyApp.API, MyApp.Services └── MyApp.Utils (unused!) Circular dependency example (bad): MyApp.Services → MyApp.Data MyApp.Data → MyApp.Services ❌ (circular!)

Visual dependency graphs make these relationships immediately obvious, whereas text lists require careful reading.

IDE Tools: Built-In Support

Visual Studio

Built-in (Enterprise)

Architecture > Dependency Diagram
Auto-generates from solution
Validate code against diagram
Only in VS Enterprise edition

// Right-click project > Architecture > Show on Dependency Diagram >
>

JetBrains Rider

Built-in (All Editions)

Tools > Architecture > Show Project Diagram
Real-time coupling analysis
Thin/thick lines for usage count
Compare snapshots over time

// Main menu Tools > Architecture > Show Project Diagram >
>
>

Enterprise Tools: Deep Analysis

Tool Price Key Features Best For
NDepend $595-990/yr Dependency graph, matrix view, CQLinq rules, code metrics, compliance reports Enterprise quality gates, CI/CD integration, legacy code audits
Visual Studio Enterprise $550/mo Dependency diagram, layer validation, code map Large teams already using VS, tight integration
Rider (Professional+) $15-25/mo Project diagram, coupling analysis, type dependency graph, snapshots Cross-platform development, JetBrains ecosystem
Resharper $10-20/mo Dependency diagram, dead code detection, architecture explorer Visual Studio plugin, existing users

Open-Source Tools

Microsoft.Cci

Parse .NET assemblies. Build custom dependency analysis tools. Low-level, requires coding.

GitHub Free

Roslyn

Official Microsoft compiler API. Analyze C# source code, detect dependencies at compile time.

GitHub Free

DependencyGraph (GitHub)

Open-source tool: marccarre/DependencyGraph. CLI tool for C# dependency visualization.

GitHub Free

VSCode Extensions

VSCode C# Dependency Graph extension. Lightweight visualization in the editor.

VSCode Free

Graphviz DOT Export

Export dependency data as Graphviz DOT files. Render with online or local Graphviz tools.

Standard Free

Mermaid Diagrams

Text-based syntax for dependency graphs. Render in GitHub, docs, or online editor.

Text-Based Free

Circular Dependencies: The Main Problem

❌ Circular Dependency (Won't Compile): // Services/UserService.cs using MyApp.Data; public class UserService { private UserRepository repo; } // Data/UserRepository.cs using MyApp.Services; public class UserRepository { private UserService service; // ❌ Circular! } Error: Circular project references detected.

How to fix: Extract shared interfaces/models into a third, independent project.

✅ Solution (Break the Cycle): // Core/IUserRepository.cs (no dependencies) public interface IUserRepository { } // Data/UserRepository.cs using MyApp.Core; public class UserRepository : IUserRepository { } // Services/UserService.cs using MyApp.Core; public class UserService { private IUserRepository repo; }

Best Practices

Use Layered Architecture

CoreDataServicesAPI. Create separate projects per layer to enforce layering.

Minimize Cross-Layer References

Core shouldn't reference API. Data shouldn't reference Services. Only downward arrows.

Use Dependency Injection

DI containers (DryIoc, Autofac, Serilog) decouple projects better than direct references.

Extract Shared Code

When two projects need the same code, create a shared project instead of creating circular dependencies.

Regular Audits

Review dependency graphs quarterly. New circular deps creep in during active development.

Enforce in CI/CD

Use NDepend or Rider in CI to fail builds on circular dependencies or unexpected coupling.

Dependency Matrix: Alternative View

Instead of a graph, some tools show a Dependency Structure Matrix (DSM)—a grid where rows and columns are projects, and cells show dependencies. This view is better for large solutions (100+ projects) because graphs become too cluttered.

NDepend and Rider both support matrix views. Visual Studio does not (Enterprise graphs only).


FAQ

Project references: In Visual Studio, when you add a reference to another .csproj (shown in Solution Explorer). Assembly references: References to compiled .dll files (NuGet packages, external libraries). Dependency graphs show both, but project references are the main focus.
No. Visual Studio's dependency diagram is only in the Enterprise edition ($550/month). For Community/Professional users, use Rider (free trial or $15/mo) or open-source tools like DependencyGraph.
A dead reference is when Project A references Project B in the .csproj, but the code never actually uses anything from B. You can safely remove the reference. Tools like Rider and NDepend detect these and show them as dotted lines.
In VS Enterprise: Right-click on the diagram → Export. Choose PNG or SVG. In Rider: Tools > Architecture > Show Project Diagram → Click Export to Image on the toolbar. Both support PNG and SVG export.
Yes, in Rider: Tools > Architecture > Compare with Saved. Save snapshots (.argr files) and compare current state to past states. NDepend: Baseline comparisons built-in. Visual Studio: No built-in diff, requires manual screenshots.
In Rider: Thick lines mean many usages. Thin lines mean few. Dotted lines mean no actual usages (dead references). You should see mostly thin solid lines. Thick lines suggest tight coupling and refactoring opportunities.
Coupling analysis means scanning actual code to count usages between projects (e.g., "Project A uses 47 types from Project B"). It's resource-intensive but gives an accurate picture of coupling strength. In Rider, it runs in the background after you open the diagram.

Quick Recommendation

Choose Based on Your Setup

👤 Individual / Small Team (2-5 people)

JetBrains Rider Community / Professional ($15/mo) — Best value, all features

🏢 Medium Team (5-30 people)

Rider Professional + NDepend ($25-30/person/mo) — IDE + enterprise analysis

🏛️ Enterprise (30+ people)

Visual Studio Enterprise + NDepend — Full integration, governance, compliance

💰 Budget-Conscious

Open-source (Roslyn, DependencyGraph) — Free, requires some coding