MathMax.Analyzers.UnusedSymbols 0.1.0

dotnet add package MathMax.Analyzers.UnusedSymbols --version 0.1.0
                    
NuGet\Install-Package MathMax.Analyzers.UnusedSymbols -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MathMax.Analyzers.UnusedSymbols" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MathMax.Analyzers.UnusedSymbols" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MathMax.Analyzers.UnusedSymbols">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MathMax.Analyzers.UnusedSymbols --version 0.1.0
                    
#r "nuget: MathMax.Analyzers.UnusedSymbols, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MathMax.Analyzers.UnusedSymbols@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MathMax.Analyzers.UnusedSymbols&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MathMax.Analyzers.UnusedSymbols&version=0.1.0
                    
Install as a Cake Tool

MathMax.Analyzers.UnusedSymbols

NuGet NuGet Downloads

A Roslyn analyzer that detects unused symbols (types, methods, properties, fields, events) in C# code. This analyzer helps maintain clean codebases by identifying declared symbols that are not referenced anywhere in the analyzed compilation.

Features

  • Comprehensive Symbol Detection: Identifies unused types, methods, properties, fields, and events
  • Smart Exclusions: Automatically excludes common externally-invoked symbols like:
    • MVC and Web API controllers
    • Public entry points
    • Symbols with special attributes
  • SOLID Design: Built with clean architecture principles for maintainability and testability
  • Performance Optimized: Uses concurrent execution for fast analysis

Installation

🔧 Option 1 — Install via NuGet package

Install the NuGet package in your project:

<PackageReference Include="MathMax.Analyzers.UnusedSymbols" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

📦 Option 2 — Install via Package Manager Console

Install-Package MathMax.Analyzers.UnusedSymbols

🧩 Option 3 — Use it as a global analyzer (no code changes)

If you don't want to modify .csproj files, you can add the analyzer as a global analyzer via MSBuild properties.

In your Directory.Build.props (in the root of your solution):

<Project>
  <ItemGroup>
    <Analyzer Include="..\Path\To\UnusedSymbolsAnalyzer.dll" />
  </ItemGroup>
</Project>

Then simply:

dotnet build

Diagnostic Rules

Rule ID Category Severity Description
USG001 Usage Warning Symbol appears to be unused

Configuration

The analyzer can be configured using an .editorconfig file:

# Enable/disable the analyzer
dotnet_diagnostic.USG001.severity = warning

# Or suppress for specific files
[{bin,obj}/**/*.cs]
dotnet_diagnostic.USG001.severity = none

Examples

The analyzer will flag unused symbols like:

public class MyClass
{
    private int _unusedField; // USG001: '_unusedField' is declared but appears to be unused
    
    private void UnusedMethod() // USG001: 'UnusedMethod' is declared but appears to be unused
    {
        // Implementation
    }
    
    public void UsedMethod() // No warning - this method is used
    {
        // Implementation
    }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

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

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 205 10/15/2025

Initial release - Detects unused symbols with USG001 diagnostic rule