Covers a real rollout plan for analysers on a legacy .NET solution with thousands of warnings: measuring and grouping warnings, deciding per rule (fix, enforce, or switch off), mechanical bulk fixes, a ratchet so the count can only fall, per-project warnings-as-errors, team agreement and progress tracking.
I wouldn't try to fix 5,000 warnings. I'd measure, stop new ones, then pay down by value.
CS8602, CA2000, CA2100), auto-fix the style ones, and switch off the noise in .editorconfig, recorded in an ADR.dotnet format PRs with no behaviour change; risky fixes (nullability, disposal) area by area with tests, boy-scout style.Trade-off: the ratchet is slower than a clean-up sprint, but it never blocks delivery and the count can only go one way.
"The first thing I'd say is that 5,000 warnings isn't a code problem, it's a signal problem: the team can't see the one warning that matters. So the goal isn't zero, it's making a new warning visible again, and then paying down the old ones by value.
For example, at [company] the [order platform] solution had about [5,200] warnings across [40] projects. In week one I took a binary log of the CI build and grouped the warnings by id and project. [Eleven] ids made up [83%]: mostly
CS8602and friends from a half-finished nullable rollout,CA2007ConfigureAwait, and a few hundred IDE style rules. I booked an hour with the team and we went through the top ids together. We agreed three buckets: rules that find real bugs, which we'd enforce; style rules we'd fix automatically withdotnet format; and rules we decided we didn't care about, likeCA2007in an ASP.NET Core app, which we switched off in.editorconfigwith the reason in an ADR. That alone took the count to about [2,900] without changing a line of code. Then I stopped the bleeding: every rule that was already at zero became an error, and I added a ratchet step to CI that compares the warning count with a baseline file in the repo and fails if it goes up. When a PR lowers it, the developer lowers the baseline in the same PR. The mechanical fixes went in as separate, behaviour-free PRs added to.git-blame-ignore-revs. Nullable and disposal warnings were fixed area by area with tests, as part of feature work in those areas plus [10%] of each sprint.The result was [5,200] to [under 300] in [four] months, [18] projects at zero with
TreatWarningsAsErrorson, and we found [two] real connection leaks along the way. The mistake I see is the opposite approach: aGlobalSuppressions.cswith 5,000 entries, orNoWarneverywhere, so the dashboard is green and the debt is invisible."
| When | Action | Outcome |
|---|---|---|
| Week 1 | Binary log, group by id and project; top ids reviewed with the team | Shared picture, agreed rule buckets |
| Week 1 | ADR: which rules are enforced, auto-fixed, switched off | A decision people can find later |
| Week 2 | Switch off agreed noise in .editorconfig; zero-count rules to error; CI ratchet |
Count drops, can't rise |
| Weeks 2–4 | dotnet format / fix-all PRs per rule, behaviour-free |
Style warnings gone |
| Ongoing | Risky fixes by area with tests; projects at zero switch to TreatWarningsAsErrors |
Steady decline, real bugs found |
| Bucket | Examples | Action |
|---|---|---|
| Real bug risk | CS8602, CA2000, CA2100, CA1849, CA2016 |
Enforce; fix with tests |
| Mechanical style | IDE0005, IDE0161, IDE0090 |
dotnet format, then enforce |
| Not valuable here | CA2007 in an ASP.NET Core app, CA1062 with nullable on |
Switch off with reason |
| Unsure | CA1031 catch general exception |
Leave as warning, revisit |
In that rollout the ratchet failed [about 15] PRs in the first month, each fixed in minutes because the new warning was in the PR's own code. Build output went from [5,200] lines of warnings to [a screenful], and the team started treating a new warning as a review comment rather than background noise.
Checks whether the candidate can lead a pragmatic, incremental quality improvement on a legacy codebase: measuring, deciding with the team, enforcing without blocking delivery, and sustaining the result.
Green flags
Red flags
NoWarn to get to greenA warning is useful only if a human notices it at the moment it is introduced. Past a few dozen, new warnings are invisible: the cost of attention is too high, so everyone ignores the whole list. This is the same mechanism as alert fatigue in operations.
warnings visible to a developer
│
10 ┤ ● every new one noticed
100 ┤ ● skimmed
1000 ┤ ● ignored
5000 ┤ ● 'the build always says that'
└──────────────────────────── time
dotnet build -bl:build.binlog and open it in the MSBuild Structured Log Viewer; the warnings view groups by code and project.-flp:"logfile=warnings.log;warningsonly", then group by the CSxxxx/CAxxxx/IDExxxx code.AnalysisLevel / AnalysisMode (Directory.Build.props) ──► which rules are on by default
▼
.editorconfig / .globalconfig dotnet_diagnostic.<id>.severity ──► per-rule override
▼
WarningsAsErrors / TreatWarningsAsErrors / NoWarn (MSBuild) ──► how warnings affect the build
▼
#pragma / [SuppressMessage] ──► single occurrence, with justification
Use .editorconfig for per-rule decisions (scoped by folder if needed, e.g. stricter in src/Domain/), WarningsAsErrors for specific ids, and TreatWarningsAsErrors only per project once that project is at zero.
A ratchet allows movement in one direction. The CI step counts unique warnings and compares with a committed warnings-baseline.txt. Higher: fail. Lower: pass, and ask the author to lower the baseline. It needs no tooling licence and works with any analyser. SonarQube's new-code gate is a richer version of the same idea.
dotnet format style --diagnostics IDE0005 IDE0161 and dotnet format analyzers --diagnostics CA1822 apply code fixes in bulk..git-blame-ignore-revs so git blame stays useful.! is a claim. Fix them with tests, or enable nullable per folder/file (#nullable enable) as each area is cleaned.The technical plan is the easy half. Agree buckets with the team, publish the trend, and make each project reaching zero a visible milestone. A rule imposed without agreement gets #pragma warning disable within a week.
dotnet format style --verify-no-changes and then apply one rule in a single PR..git-blame-ignore-revs file and configure git config blame.ignoreRevsFile.TreatWarningsAsErrors, and measure how long it stays green.Build settings that stop new problems without breaking the existing build.
<!-- Directory.Build.props -->
<Project>
<PropertyGroup>
<AnalysisLevel>10.0-recommended</AnalysisLevel> <!-- pinned: SDK upgrades don't move the bar -->
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<!-- Rules already at zero: any new occurrence fails the build -->
<WarningsAsErrors>$(WarningsAsErrors);CA2000;CA2100;CA2016;CS8600;CS8602;CS8604</WarningsAsErrors>
</PropertyGroup>
<!-- Projects that reached zero opt in to the strict mode -->
<PropertyGroup Condition="'$(StrictWarnings)' == 'true'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
</Project>
# .editorconfig: decisions from ADR-0031 (analyser rollout)
root = true
[*.cs]
# Not valuable in ASP.NET Core apps (no SynchronizationContext)
dotnet_diagnostic.CA2007.severity = none
# Redundant once nullable is on in a project
dotnet_diagnostic.CA1062.severity = none
# Mechanical: fixed by dotnet format, then enforced
dotnet_diagnostic.IDE0005.severity = warning
[src/Billing.Domain/**.cs]
# Stricter where the money is
dotnet_diagnostic.CA1305.severity = error
#!/usr/bin/env bash
# ci/warnings-ratchet.sh: fail if the warning count rises above the committed baseline
set -euo pipefail
dotnet build Orders.slnx -c Release --no-incremental \
-flp:"logfile=warnings.log;warningsonly" > /dev/null
# Unique warnings (multi-targeting reports duplicates)
count=$(grep -E 'warning (CS|CA|IDE|SA|S)[0-9]+' warnings.log | sort -u | wc -l)
baseline=$(cat warnings-baseline.txt)
echo "Warnings: $count (baseline $baseline)"
if (( count > baseline )); then
echo "New warnings introduced. Top ids:"
grep -oE 'warning (CS|CA|IDE|SA|S)[0-9]+' warnings.log | sort | uniq -c | sort -rn | head
exit 1
elif (( count < baseline )); then
echo "Nice: please lower warnings-baseline.txt to $count in this PR."
fi
A behaviour-free fix PR, before and after:
// Before: CS8602 + CA2000 in OrderExporter
public string Export(Order order)
{
var writer = new StringWriter();
writer.Write(order.Customer.Name); // Customer may be null
return writer.ToString();
}
// After: fixed with a test for the null-customer case
public string Export(Order order)
{
using var writer = new StringWriter(CultureInfo.InvariantCulture);
writer.Write(order.Customer?.Name ?? "(guest)");
return writer.ToString();
}
TreatWarningsAsErrors for the whole solution on day one. Why it is wrong: nothing builds, so it gets reverted or NoWarn grows. Instead: errors for zero-count rules, and per project once at zero.GlobalSuppressions.cs with thousands of entries. Why it is wrong: the debt becomes invisible and future occurrences in those members are hidden too. Instead: a ratchet baseline that only goes down.!. Why it is wrong: each ! is an untested claim that can become a NullReferenceException. Instead: fix the flow, add tests, enable nullable per area..git-blame-ignore-revs.AnalysisLevel unpinned. Why it is wrong: an SDK upgrade adds new rules and breaks the ratchet overnight. Instead: pin it and raise it deliberately.The senior move is to reframe the goal from 'zero warnings' to 'every new warning is seen', because that can be achieved in a week and the rest becomes routine. The drop from thousands to a few thousand by switching off noise looks free, but it only works because the team made those decisions together: that session is where buy-in comes from, and it also levels knowledge. Newer developers often can't tell which warnings matter, while experienced ones have learned to ignore all of them; walking through the top ids together, with a real incident as the example, fixes both.
Prioritise by risk. I rank rules by what they protect: anything linked to a past incident, rules guarding money, personal data, resources and security first; style last. Critical modules (billing, auth) get stricter severities via folder-scoped .editorconfig sections. Making zero-count rules errors is safe because no existing code breaks, but I still announce it and explain each rule so the first failed PR isn't a surprise.
I choose mechanisms that can't be quietly undone (a ratchet in CI, errors for clean rules, TreatWarningsAsErrors per project as each reaches zero), agree a small sprint budget with the product owner, and report progress in terms of risk found (e.g. connection leaks, null crashes avoided), not warnings fixed.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| Ratchet on warning count | Any legacy solution, no extra tooling | A script and a baseline file | When the count is already near zero (just use errors) |
| SonarQube new-code gate | Already using Sonar, want per-line attribution | Licence for PR analysis | Only to replace build errors for clean rules |
TreatWarningsAsErrors everywhere |
New or clean solutions | Blocks on any warning, including SDK upgrades | Legacy code with thousands of warnings |
| Mass suppression file | Almost never; maybe a generated code folder | Hides debt | Hand-written code |
| Clean-up sprint | Small solution, a few hundred mechanical warnings | One sprint of no features | Thousands of warnings or risky fixes |
The file under review turns on TreatWarningsAsErrors and then hides 25 warnings with NoWarn. That list includes nullable warnings, obsolete-API warnings and a security rule, so the policy looks strict while silencing the warnings that matter most. I'd remove those suppressions. Rules that genuinely don't apply would get a severity in .editorconfig, scoped to the right folders and commented. Rules we can't fix yet would go in WarningsNotAsErrors, so they stay visible as warnings. I'd also pin AnalysisLevel so an SDK upgrade can't break the build overnight, apply the same settings locally and in CI, and ratchet a legacy codebase towards zero warnings rather than flipping everything at once.
<Nullable>enable</Nullable> makes reference types non-nullable by default: string? means a value can be null and string means it can't. The compiler then warns when code might dereference null. It's purely compile-time, so nothing changes at run time. In a big codebase I migrate bottom-up: shared libraries and domain types first, because their annotations flow out to everyone else. I go project by project, or file by file with #nullable enable, and give each step a small pull request so feature work carries on. When a project is clean I make its nullable warnings errors with WarningsAsErrors=nullable, so it can't slip back. I use attributes such as [NotNullWhen] where flow analysis needs help and keep ! for real boundaries. I also watch for two things: EF Core migrations, where nullability decides whether columns are required, and public APIs, where annotations are part of the contract.
Technical debt is the future cost of a shortcut, and the interest is the extra effort or risk it adds every time we work near it. I make it visible in a debt register with each item's impact, how often we pay its interest (change frequency, incidents, delays) and a rough cost to fix. I prioritise by interest, not by how ugly the code is: debt in a hotspot that slows every feature beats a messy module nobody touches. I get time by explaining it in business terms (lead time, incident risk, cost), by reserving a steady share of capacity, and by pairing debt fixes with features that touch the same area.
How to tell it (STAR)
**S:** At [company] our main solution printed about [5,200] warnings and a connection leak that `CA2000` had flagged a year earlier had just caused an outage. **T:** I was asked to make analysers useful again without pausing feature work. **A:** I grouped the warnings by rule, agreed with the team which to enforce, auto-fix or switch off, added a CI ratchet so the count couldn't rise, made clean rules errors, and paid down the risky ones area by area with tests. **R:** In [four] months we went from [5,200] to [under 300], [18] projects run with warnings as errors, and we found [two] more real connection leaks before they reached production.
Last updated 23 Nov 2026.