add-net-analyzer

Implements and ports .NET CA code analysis rules with fixers, tests, and release tracking.

1.2k|337|Updated Oct 13, 2022
One-click install
npx skills add https://github.com/dotnet/dotnet --skill add-net-analyzer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: add-net-analyzer
Source: https://github.com/dotnet/dotnet/tree/main/src/sdk/.github/skills/add-net-analyzer
Command: npx skills add https://github.com/dotnet/dotnet --skill add-net-analyzer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

Adding a new .NET code analysis (CA####) rule to the NetAnalyzers package involves many error-prone steps: allocating an unclaimed diagnostic ID, wiring resx/xlf localization, recording the rule in release tracking, and writing analyzer/code-fix tests. This Skill guides the entire workflow so nothing is missed.

Core Features & Use Cases

  • Diagnostic ID allocation: Runs a script that scans the working tree, local branches, and open dotnet/sdk PRs to propose a free CA ID and prints the exact range edit.
  • Authoring guidance: Provides patterns for writing language-agnostic analyzers, code fixers, fix-all providers, and MSTest tests with the VerifyCS/VerifyVB harness.
  • Porting support: Maps paths and conventions for porting rules or PRs from the retired dotnet/roslyn-analyzers repository.
  • Use Case: You want to add a new performance analyzer CA1878 with a code fix. The Skill walks you through ID allocation, descriptor creation with RuleLevel, resx/xlf string generation, AnalyzerReleases.Unshipped.md tracking, and test coverage requirements.

Quick Start

Ask the assistant to add a new CA analyzer rule for a specific performance or reliability pattern in the NetAnalyzers project.

Frequently Asked Questions about add-net-analyzer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new CA analyzer rule to dotnet/sdk?

Allocate a free diagnostic ID with the NextDiagnosticId.cs script, implement the analyzer and fixer under src/Microsoft.CodeAnalysis.NetAnalyzers, add resx strings and regenerate xlf files, record the rule in AnalyzerReleases.Unshipped.md, and write MSTest code-fix tests.

How do I port an analyzer from dotnet/roslyn-analyzers?

Fetch the archived source via gh api with a pinned ref, translate paths from src/NetAnalyzers to src/Microsoft.CodeAnalysis.NetAnalyzers, re-allocate the rule ID since upstream IDs are often taken, and convert xUnit tests to MSTest.

How is a CA diagnostic ID allocated without collisions?

Run NextDiagnosticId.cs with the category name. It scans forward from the category range end, checking the working tree, all local branches, and open dotnet/sdk PR titles and bodies, then prints the exact DiagnosticCategoryAndIdRanges.txt edit.

Does this Skill cover NETSDK or compiler diagnostics?

No. It explicitly excludes NETSDK#### MSBuild diagnostics in src/Tasks, CS####/BC#### compiler diagnostics and IDE#### analyzers in dotnet/roslyn, and CONTAINER#### diagnostics. It only covers CA#### rules in NetAnalyzers.

Why does the build fail with RS2000 or RS2001 after adding a rule?

The RS2000/RS2001 meta-analyzers require every new rule to be recorded in AnalyzerReleases.Unshipped.md for the project declaring the descriptor. They ship a code fix that writes the row for you with the correct severity mapping.