C# Dependency Graph
Generate interactive dependency graphs for C# projects and classes directly from Visual Studio Code.
Change Log
See CHANGELOG.md for a list of changes in README.md
Features
- Project-level dependency visualization: See how your C# projects depend on each other
- Class-level dependency analysis: Analyze dependencies between classes across your solution
- Solution file support: Automatically detect and use .sln files to find all projects in a solution structure
- Customizable output: Configure which elements to include in your dependency graph
- Exclude test projects: Option to exclude test projects from the analysis
- DOT file output: Generate standard DOT files for use with internal preview feature or other visualization tools like Graphviz
- Preview Graphviz: Preview Graphviz on graphviz file open (beta)
- Preview configuration options: Preview configuration options in settings
Screenshots
Project Dependencies

Select view->Command Palette: C#: Generate Dependency Graph
and select Project Dependencies
Graph is generated in the selected folder. You can open it in Graphviz, Graphviz Online or Graphviz Preview
Class Dependencies
Select view->Command Palette: C#: Generate Dependency Graph
and select Class Dependencies
Graph is generated in the selected folder. You can open it in Graphviz, Graphviz Online or Graphviz Preview

Installation
From VS Code Marketplace
- Open VS Code
- Go to Extensions (Ctrl+Shift+X)
- Search for "C# Dependency Graph"
- Click Install
Manual Installation
- Download the .vsix file from the releases page
- In VS Code, go to Extensions (Ctrl+Shift+X)
- Click on the "..." menu (top-right) and select "Install from VSIX..."
- Select the downloaded .vsix file
Requirements
- Visual Studio Code 1.75.0 or higher
- A C# project (typically a .NET solution with .csproj files)
Usage
Generating a Dependency Graph
- Open a folder containing C# projects in VS Code
- Press
Ctrl+Shift+P
to open the command palette
- Type "C#: Generate Dependency Graph" and select the command
- If solution (.sln) files are found, you'll be asked if you want to use one of them
- Choose the type of dependency graph:
- Project Dependencies: Shows relationships between projects
- Class Dependencies: Shows detailed relationships between classes
- Select where to save the .dot file
- The graph will be generated and saved to the specified location
Viewing the Graph

You can view the generated .dot file using:
Example Class Dependency Graph
Here's an example of a class dependency graph generated by the extension:

Extension Settings
This extension contributes the following settings:
csharpDependencyGraph.useSolutionFile
: Enable or disable using .sln files to identify projects (default: true)
csharpDependencyGraph.includeNetVersion
: Include .NET framework version in project nodes (default: true)
csharpDependencyGraph.includePackageDependenciesInProjectGraph
: Include NuGet package dependencies in the project dependency graph (default: false)
csharpDependencyGraph.classDependencyColor
: Color for the classes in class dependency graph (default: lightgray)
csharpDependencyGraph.packageDependencyColor
: Color for the packages in project dependency graph (default: #ffcccc)
csharpDependencyGraph.excludeTestProjects
: Exclude test projects from the dependency graph (default: true)
csharpDependencyGraph.testProjectPatterns
: Glob patterns to identify test projects
csharpDependencyGraph.excludeSourcePatterns
: Glob patterns for source files to exclude from analysis
csharpDependencyGraph.openPreviewOnGraphvizFileOpen
: Enable or disable previewing Graphviz on graphviz file open (default: true)

How It Works
The extension works by:
- Finding and parsing .sln files (if enabled) or searching for all .csproj files in the workspace
- Parsing the project files to extract project references
- For class-level analysis, parsing all C# files to extract class dependencies including:
- Inheritance relationships
- Field and property types
- Method parameter and return types
- Static method calls
- Object instantiations
- Generating a DOT file representation of the dependency graph
Code organization
classDiagram
direction LR
class Extension {
+activate(context: vscode.ExtensionContext)
}
class GraphGenerator {
+generateDotFile(projects: Project[], options: GraphOptions, classDependencies?: ClassDependency[]): string
+generateClassDependencyGraph(projects: Project[], classDependencies: ClassDependency[], options: GraphOptions): string
}
class CsprojFinder {
+findCsprojFiles(workspaceFolder: string, excludeTestProjects: boolean, testProjectPatterns: string[], useSolutionFile: boolean): Promise<string[]>
}
class CsprojParser {
+parseCsprojFiles(csprojPaths: string[]): Promise<Project[]>
}
class SlnParser {
+findSolutionFiles(directoryPath: string): Promise<string[]>
+parseSolutionFile(slnFilePath: string): Promise<string[]>
}
class CsharpSourceFinder {
+findCSharpSourceFiles(workspaceFolder: string): Promise<string[]>
}
class CsharpClassParser {
+parseClassDependencies(sourceFiles: string[]): Promise<ClassDependency[]>
}
class GraphPreviewProvider {
+showPreview(dotContent: string, title: string): void
-_updateContent(dotContent: string): void
}
class VizInitializer {
+prepareVizJs(extensionUri: vscode.Uri): Promise<boolean>
}
Extension --> GraphGenerator
Extension --> CsprojFinder
Extension --> CsprojParser
Extension --> CsharpSourceFinder
Extension --> CsharpClassParser
Extension --> SlnParser
Extension --> GraphPreviewProvider
Extension --> VizInitializer
CsprojFinder --> SlnParser
GraphPreview ..> VizInitializer: uses
Known Issues
- Very large codebases with many classes may generate complex graphs that are difficult to render
- Some complex C# syntax constructs might not be correctly parsed for class dependencies
- The extension currently only analyzes direct project references in .csproj files, not transitive package references
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This extension is licensed under the MIT License.