dotnet-code-analysis
Skill13 starsChanged 8 months agoMITView on GitHub
Use the free built-in .NET SDK analyzers and analysis levels with gradual Roslyn warning promotion. Use when a .NET repo needs first-party code analysis, `EnableNETAnalyzers`, `AnalysisLevel`, or warning-as-error policy wired into build and CI.
In this repository84 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- dotnet-analyzer-configSkill
- dotnet-architectureSkill
- dotnet-archunitnetSkill
- dotnet-aspireSkill
- dotnet-aspnet-coreSkill
- dotnet-asynkron-profilerSkill
- dotnet-azure-functionsSkill
- dotnet-biomeSkill
- dotnet-blazorSkill
- dotnet-chousSkill
- dotnet-clocSkill
- dotnet-codeqlSkill
- dotnet-code-reviewSkill
- dotnet-complexitySkill
- dotnet-coverletSkill
- dotnet-csharpierSkill
- dotnet-entity-framework6Skill
- dotnet-entity-framework-coreSkill
- dotnet-eslintSkill
- dotnet-formatSkill
- dotnet-grpcSkill
- dotnet-htmlhintSkill
- dotnet-legacy-aspnetSkill
- dotnet-libvlcSkill
- dotnet-managedcode-communicationSkill
- dotnet-managedcode-markitdownSkill
- dotnet-managedcode-mimetypesSkill
- dotnet-managedcode-orleans-graphSkill
- dotnet-managedcode-orleans-signalrSkill
- dotnet-managedcode-storageSkill
- dotnet-mauiSkill
- dotnet-mcaf-agile-deliverySkill
- dotnet-mcaf-devexSkill
- dotnet-mcaf-documentationSkill
- dotnet-mcaf-feature-specSkill
- dotnet-mcaf-human-review-planningSkill
- dotnet-mcaf-ml-ai-deliverySkill
- dotnet-mcaf-nfrSkill
- dotnet-mcafSkill
- dotnet-mcaf-source-controlSkill
- dotnet-mcaf-ui-uxSkill
- dotnet-mcpSkill
- dotnet-metalintSkill
- dotnet-meziantou-analyzerSkill
- dotnet-microsoft-agent-frameworkSkill
- dotnet-microsoft-extensions-aiSkill
- dotnet-microsoft-extensionsSkill
- dotnet-minimal-apisSkill
- dotnet-mixed-realitySkill
- dotnet-mlnetSkill
- dotnet-modern-csharpSkill
- dotnet-mstestSkill
- dotnet-mvvmSkill
- dotnet-netarchtestSkill
- dotnet-nunitSkill
- dotnet-orleansSkill
- dotnet-profilingSkill
- dotnet-project-setupSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
Never disable or remove TreatWarningsAsErrors or WarningsAsErrors if the project has set them.
- Very specific: line 34
Never add <NoWarn> or #pragma warning disable for warnings the user chose to treat as errors, unless the user explicitly approves the …
- Very specific: line 35
Never silently downgrade severity in .editorconfig (e.g.
- Distinctive: line 36
If warnings-as-errors breaks the build — fix the code.
- Distinctive: line 37
If warning volume is too large to fix in one pass — report count and categories to the user and ask which to tackle first.
- Distinctive: line 60
Start with SDK analyzers before third-party packages.
- Very specific: line 92
Add to WarningsAsErrors: CS8019;CS0219;CS0168.
- Very specific: line 104
Ask: "Which categories next — Nullability, Performance, or Reliability?" Add selected IDs to WarningsAsErrors, fix, repeat.
- Very specific: line 126
Run dotnet build, count warnings by ID.
- Distinctive: line 128
Ask which batch to tackle.
- Very specific: line 130
Add those IDs to WarningsAsErrors.
- Distinctive: line 133
Never skip the ask step. The user decides the pace.
- Very specific: line 145
Run dotnet build, return status: configured or status: improved.
- Very specific: line 146
If repo defers analyzer policy to another build layer, return status: not_applicable.
- Distinctive: line 167
Update plan after each iteration.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
.NET Code Analysis
Trigger On
- the repo wants first-party .NET analyzers
- CI should fail on analyzer warnings
- the team needs
AnalysisLevelorAnalysisModeguidance - the repo needs a gradual Roslyn warning promotion strategy
Do Not Use For
- third-party analyzer selection by itself
- formatting-only work
Inputs
- the nearest
AGENTS.md - project files or
Directory.Build.props - current analyzer severity policy
Hard Rules for AI Agents
Non-negotiable. Violating these undermines the user's explicit intent.
- Never disable or remove
TreatWarningsAsErrorsorWarningsAsErrorsif the project has set them. Do not comment them out, set tofalse, wrap in a condition, or add<TreatWarningsAsErrors>false</TreatWarningsAsErrors>to make the build pass. - Never add
<NoWarn>or#pragma warning disablefor warnings the user chose to treat as errors, unless the user explicitly approves the suppression. - Never silently downgrade severity in
.editorconfig(e.g.errortowarningornone) to make a build succeed. - If warnings-as-errors breaks the build — fix the code. If the fix is too large, ask the user whether to defer that warning ID.
- If warning volume is too large to fix in one pass — report count and categories to the user and ask which to tackle first. Do not unilaterally disable the policy.
Workflow
flowchart TD
A[Start] --> B{New or legacy project?}
B -->|New| C[TreatWarningsAsErrors=true immediately]
B -->|Legacy| D[dotnet build, count warnings by ID]
D --> E{"< 30 warnings?"}
E -->|Yes| F[Fix all, then enable TreatWarningsAsErrors]
E -->|No| G[Report counts to user, ask which batch first]
G --> H[Add selected IDs to WarningsAsErrors]
H --> I[Fix that batch, verify build]
I --> J{More batches?}
J -->|Yes| G
J -->|No| F
C --> K[Set AnalysisLevel latest-recommended]
F --> K
K --> L[Promote security CA3xxx/CA5xxx to error in .editorconfig]
L --> M[Validate: build + CI green]- Start with SDK analyzers before third-party packages.
- Detect project maturity: new or existing/legacy.
- Enable
EnableNETAnalyzers,AnalysisLevel,AnalysisModeinDirectory.Build.props. - Apply the right warning promotion strategy (see below).
- Per-rule severity goes in repo-root
.editorconfig. dotnet buildis the analyzer gate in CI.
Warning Promotion Strategy
New Projects
Set these in Directory.Build.props immediately:
TreatWarningsAsErrors= trueAnalysisLevel= latest-recommended- Security category = error in
.editorconfig
Fix all warnings before merging.
Legacy Projects — Gradual Promotion
Blanket TreatWarningsAsErrors on a legacy codebase produces hundreds/thousands of errors. An agent cannot fix them all at once — context floods, fix quality drops. Promote in batches.
Phase 1: Trivial Hygiene (start here)
Mechanical fixes, lowest effort:
- CS8019 — unnecessary using directive (remove it)
- CS0219 — variable assigned but never used (remove it)
- CS0168 — variable declared but never used (remove it)
- CS1591 — missing XML comment for public member (add comment or disable for internal code)
- CS0612 — obsolete member used, no message (replace with non-obsolete API)
- CS0618 — obsolete member used, with message (follow migration guidance)
Add to WarningsAsErrors: CS8019;CS0219;CS0168. Fix all, then Phase 2.
Phase 2: Code Quality (ask user which categories)
- CA2000 — dispose objects before losing scope (Reliability)
- CA1062 — validate public method arguments (Design)
- CA1822 — mark members as static (Performance)
- CA1860 — avoid Enumerable.Any() for length check (Performance)
- CA1861 — avoid constant arrays as arguments (Performance)
- CA2007 — consider calling ConfigureAwait (Reliability)
- CS8600–CS8610 — nullable reference type warnings (Nullability)
Ask: "Which categories next — Nullability, Performance, or Reliability?" Add selected IDs to WarningsAsErrors, fix, repeat.
Phase 3: Security (always promote early)
Set in .editorconfig regardless of project maturity:
[*.cs]
dotnet_analyzer_diagnostic.category-Security.severity = errorCovers CA3001 (SQL injection), CA3002 (XSS), CA3003 (path injection), CA3075 (insecure DTD), CA5350/CA5351 (weak crypto), CA5394 (insecure randomness).
Phase 4: Full Coverage
Once all batches pass, transition to:
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsNotAsErrors>CA1707</WarningsNotAsErrors> <!-- explicit exceptions only -->Interaction Protocol (legacy codebases)
- Run
dotnet build, count warnings by ID. - Report summary: "Found 47 CS8019, 23 CA1822, 12 CA2000, 8 CS8600."
- Ask which batch to tackle. Recommend starting with Phase 1.
- Fix selected batch, verify build.
- Add those IDs to
WarningsAsErrors. - Report back, ask about next batch.
Never skip the ask step. The user decides the pace.
Bootstrap When Missing
- Detect current state:
dotnet --inforg -n "EnableNETAnalyzers|AnalysisLevel|AnalysisMode|TreatWarningsAsErrors|WarningsAsErrors" -g '*.csproj' -g 'Directory.Build.*' .dotnet build SOLUTION_OR_PROJECT 2>&1— count warnings by ID
- Classify: new (few/zero warnings) vs legacy (many warnings).
- Enable
EnableNETAnalyzers,AnalysisLevel,AnalysisModein MSBuild config. - Apply promotion strategy matching project maturity.
- Per-rule severity in repo-root
.editorconfig. - Run
dotnet build, returnstatus: configuredorstatus: improved. - If repo defers analyzer policy to another build layer, return
status: not_applicable.
Deliver
- explicit, reviewable first-party analyzer policy
- build-time analyzer execution for CI
- warning promotion plan matching project maturity
Validate
- analyzer behavior driven by repo config, not IDE defaults
- CI reproduces same warnings/errors locally
- no
TreatWarningsAsErrors,WarningsAsErrors, or severity settings removed/weakened without user approval - promoted warnings produce build errors, not just IDE hints
Ralph Loop
- Plan: analyze state, define target, constraints, risks, execution plan, validation steps.
- Execute one step, produce concrete delta.
- Review result, capture findings.
- Apply fixes in small batches, rerun checks.
- Update plan after each iteration.
- Repeat until acceptable or only explicit exceptions remain.
- Missing dependency: bootstrap or return
status: not_applicable.
Required Result Format
status:complete|clean|improved|configured|not_applicable|blockedplan: concise plan and current stepactions_taken: concrete changesvalidation_skills: final skills run or skipped with reasonsverification: commands, checks, or review evidenceremaining: unresolved items ornone
Load References
references/rules.mdreferences/config.mdreferences/code-analysis.md
Example Requests
- "Turn on built-in .NET analyzers."
- "Make analyzer warnings fail the build."
- "Set the right AnalysisLevel for this repo."
- "Start treating unused usings and unused variables as errors."
- "Help me gradually promote Roslyn warnings in my legacy project."
- "Which warnings should I promote to errors next?"
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

