Dotnet Unused Code Analyzer - VS Code Extension
Detect and highlight unused code in .NET solutions directly in Visual Studio Code using Roslyn static analysis.
Features
- On-Demand Analysis: Analyze your entire workspace or just the current file
- Inline Diagnostics: See unused code warnings directly in your editor with squiggly underlines
- Problems Panel: All unused symbols listed in VS Code's Problems panel
- Tree View: Sidebar panel showing unused symbols organized by type (Methods, Properties, Fields)
- Configurable Severity: Set diagnostic severity (Error, Warning, Information, Hint)
- Jump to Definition: Click any unused symbol in the tree view to navigate to its location
- Export Reports: Generate JSON reports of unused code (coming soon)
Requirements
This extension requires the dotnet-unused CLI tool to be installed:
dotnet tool install --global DotnetUnused
See the CLI installation guide for more options.
Usage
Commands
Access commands via Command Palette (Ctrl+Shift+P / Cmd+Shift+P):
- Dotnet Unused: Analyze Workspace for Unused Code - Analyze entire solution/project
- Dotnet Unused: Analyze Current File for Unused Code - Analyze only the current C# file's project
- Dotnet Unused: Clear Unused Code Diagnostics - Clear all diagnostics from the editor
- Dotnet Unused: Export Unused Code Report (JSON) - Export analysis results (coming soon)
Tree View
The "Dotnet Unused" sidebar panel shows:
- Unused symbols grouped by type (Methods, Properties, Fields)
- File location and line number for each symbol
- Click any item to jump to its definition
Right-click on .sln or .csproj files in the Explorer to analyze them directly.
Extension Settings
Configure the extension in VS Code settings:
dotnet-unused.cliPath: Path to dotnet-unused CLI tool (leave empty for global installation)
dotnet-unused.excludePublic: Exclude public members from detection (default: true)
dotnet-unused.diagnosticSeverity: Severity level for diagnostics (Error, Warning, Information, Hint)
dotnet-unused.useTerminal: Show output in integrated terminal instead of output window (default: true)
dotnet-unused.autoRunOnSave: Automatically analyze when C# files are saved (default: false)
How It Works
The extension integrates with the dotnet-unused CLI tool:
- Runs analysis on your .NET solution or project
- Parses the JSON output from the CLI
- Creates VS Code diagnostics for unused symbols
- Updates the tree view with results
- Allows navigation to unused code locations
Supported Project Types
- .NET Core 2.0+
- .NET 5+
- .NET 6/7/8/9+
- .NET Framework 4.x (requires Visual Studio MSBuild)
- SDK-style projects
- Legacy .csproj format
Known Limitations
- Static analysis only - does not detect runtime or reflection-based usage
- Conservative approach may miss some unused code to avoid false positives
- No incremental analysis - full solution analysis on each run
Troubleshooting
Install the CLI tool globally:
dotnet tool install --global DotnetUnused
Or specify a custom path in settings:
{
"dotnet-unused.cliPath": "/path/to/dotnet-unused"
}
Analysis is slow
- Use "Analyze Current File" for faster feedback
- Disable
autoRunOnSave for large solutions
- Consider analyzing only specific projects instead of entire solutions
Contributing
Issues and contributions welcome at GitHub.
License
MIT - See LICENSE file for details.