Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
4fa1bb5
Add initial implementation of C# Dependency Graph extension with conf…
magic5644 Feb 27, 2025
97efff2
Add class dependency analysis and configuration options to C# Depende…
magic5644 Feb 27, 2025
0a6ddd4
Update README.md to enhance feature descriptions and installation ins…
magic5644 Feb 27, 2025
ca0acab
Add icon for C# Dependency Graph extension in package.json and resources
glebournault Feb 28, 2025
b418d59
Add icon and update README for C# Dependency Graph extension
magic5644 Feb 28, 2025
8fb4bea
Rename extension package to magic-vscode-csharp-dependency-graph
glebournault Mar 3, 2025
0e1027c
Add GitHub Actions workflow for build, test, and packaging
glebournault Mar 3, 2025
cf6d6d2
Add example graph image and update documentation
magic5644 Mar 6, 2025
9861698
Fix regex to correctly capture namespaces with dots in C# class parser
magic5644 Mar 6, 2025
e19bdd3
Refactor C# class parser to improve regex patterns and update ESLint …
magic5644 Mar 6, 2025
8dd5fc8
Improve regex for extracting inheritance dependencies in C# class parser
magic5644 Mar 6, 2025
01549d3
Fix regex in extractInheritanceDependencies to correctly capture inhe…
magic5644 Mar 6, 2025
b0a47ec
Comment out command execution test in extension test suite for clarity
magic5644 Mar 6, 2025
7934fe6
Update GitHub Actions workflow and package configuration
magic5644 Mar 6, 2025
a5c79ac
Add ProjectA and ProjectB with initial implementations and dependencies
magic5644 Mar 6, 2025
8b9f50e
Remove unnecessary assembly info and cache files; update .gitignore a…
magic5644 Mar 6, 2025
062e32f
Update README, package.json, and add new resources; replace icon, enh…
glebournault Mar 7, 2025
8f7b105
Update package.json publisher and activation events; enhance extensio…
glebournault Mar 8, 2025
5636f5f
Enable publishing to VS Code Marketplace in GitHub Actions workflow
glebournault Mar 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 2020,
sourceType: 'commonjs',
project: './tsconfig.json'
},
plugins: ['@typescript-eslint'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended'
],
rules: {
'@typescript-eslint/no-explicit-any': 'warn',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-unused-vars': ['warn', {
'argsIgnorePattern': '^_',
'varsIgnorePattern': '^_'
}]
},
ignorePatterns: ['out', 'dist', '**/*.d.ts', 'node_modules']
};
1 change: 1 addition & 0 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Think step by step, but only keep a minimum draft for each thinking step, with 5 words at most. Return the answer at the end of the response after a separator ####
32 changes: 32 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '18.x'
- name: Install Dependencies
run: npm install
- name: Compile
run: npm run compile
- name: Run Tests
run: xvfb-run -a npm run test
- name: Package
run: npm run package
- name: Publish to VS Code Marketplace
if: github.ref == 'refs/heads/main'
run: |
npm install -g vsce
vsce publish -p ${{ secrets.VSCE_PAT }}
45 changes: 45 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Dependency directories
node_modules/

# Compiled output
out/
dist/
*.vsix
test-workspace/ProjectA/obj/
test-workspace/ProjectA/bin/
test-workspace/ProjectA/Debug/
test-workspace/ProjectA/Release/
test-workspace/ProjectB/obj/
test-workspace/ProjectB/bin/
test-workspace/ProjectB/Debug/
test-workspace/ProjectB/Release/

# TypeScript incremental compilation cache
*.tsbuildinfo

# VS Code specific files
.vscode-test/
.vscode/**
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Environment / local files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local

# OS specific files
.DS_Store
Thumbs.db
10 changes: 10 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [


]
}
9 changes: 9 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
src/**
out/test/**
test/**
.gitignore
tsconfig.json
**/*.map
**/*.ts
169 changes: 167 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,167 @@
# vscode-csharp-dependency-graph
A simple VS Code extension that generates a graph of your project dependencies.
# C# Dependency Graph

<p align="center">
<img src="resources/icon.png" width="128" height="128" alt="C# Dependency Graph Extension Icon">
</p>

Generate interactive dependency graphs for C# projects and classes directly from Visual Studio Code.

## 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
- **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 Graphviz or other visualization tools

## Screenshots

### Project Dependencies

![Project Dependencies](resources/csharp-project-dependencies.gif)

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

![Class Dependencies](resources/csharp-class-dependencies.gif)

Another example of class dependencies
![C# Dependency Graph](resources/graph_example.png)

## Installation

### From VS Code Marketplace

1. Open VS Code
2. Go to Extensions (Ctrl+Shift+X)
3. Search for "C# Dependency Graph"
4. Click Install

### Manual Installation

1. Download the .vsix file from the [releases page](https://github.com/yourusername/vscode-csharp-dependency-graph/releases)
2. In VS Code, go to Extensions (Ctrl+Shift+X)
3. Click on the "..." menu (top-right) and select "Install from VSIX..."
4. 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

1. Open a folder containing C# projects in VS Code
2. Press `Ctrl+Shift+P` to open the command palette
3. Type "C#: Generate Dependency Graph" and select the command
4. Choose the type of dependency graph:
- **Project Dependencies**: Shows relationships between projects
- **Class Dependencies**: Shows detailed relationships between classes
5. Select where to save the .dot file
6. The graph will be generated and saved to the specified location

### Viewing the Graph

You can view the generated .dot file using:

- VS Code extensions like [Graphviz Preview](https://marketplace.visualstudio.com/items?itemName=EFanZh.graphviz-preview)
- Online tools like [Graphviz Online](https://dreampuf.github.io/GraphvizOnline/)
- Desktop applications like [Graphviz](https://graphviz.org/)

### 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.includeNetVersion`: Include .NET framework version in project nodes
- `csharpDependencyGraph.excludeTestProjects`: Exclude test projects from the dependency graph
- `csharpDependencyGraph.testProjectPatterns`: Glob patterns to identify test projects
- `csharpDependencyGraph.includeClassDependencies`: Include class-level dependencies in the graph
- `csharpDependencyGraph.excludeSourcePatterns`: Glob patterns for source files to exclude from analysis

## How It Works

The extension works by:

1. Finding all .csproj files in the workspace
2. Parsing the project files to extract project references
3. 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
4. Generating a DOT file representation of the dependency graph

## Code organization

```mermaid
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: vscode.WorkspaceFolder): Promise<string[]>
}

class CsprojParser {
+parseCsprojFiles(csprojPaths: string[]): Promise<Project[]>
}

class CsharpSourceFinder {
+findCSharpSourceFiles(workspaceFolder: vscode.WorkspaceFolder): Promise<string[]>
}

class CsharpClassParser {
+parseClassDependencies(sourceFiles: string[]): Promise<ClassDependency[]>
}

Extension --> GraphGenerator
Extension --> CsprojFinder
Extension --> CsprojParser
Extension --> CsharpSourceFinder
Extension --> CsharpClassParser
```

## 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

## Release Notes

### 0.1.0

Initial release:

- Project dependency graph generation
- Class dependency graph generation
- Customizable graph output
- Test project filtering

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This extension is licensed under the [MIT License](LICENSE).
65 changes: 65 additions & 0 deletions icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading