skip to content

As the lead of a 40-project .NET solution, what build policy would you set for warnings as errors, AnalysisLevel and suppressions, and how would you roll it out?

level: principalimportance: should knowfreq 30%

answer

  1. one place for the rules
  2. pin, then raise on purpose
  3. local friction versus CI surprises
  4. ratchet, not big bang
  5. suppressions get reviewed

basics

~10 s

Centralise the settings in Directory.Build.props and one shared analyzer config, pin AnalysisLevel, make warnings errors at least in CI, and tighten project by project. Allow only narrow, justified suppressions, and review them like code.

solid answer

~40 s

I would put the policy in one `Directory.Build.props` and one shared `.globalconfig` or root `.editorconfig`, so the 40 projects do not drift apart. I would pin `AnalysisLevel`, say `10.0-recommended`, so a retarget or SDK update never adds rules on its own; raising it becomes a planned change. Warnings would fail the build in CI through `TreatWarningsAsErrors`, conditioned on `ContinuousIntegrationBuild`, with a short list, such as `nullable`, in `WarningsAsErrors` on every machine. Existing debt gets measured and ratcheted: clean projects go strict first, the rest carry a temporary `WarningsNotAsErrors` list that only shrinks. Suppressions would need ids and a restore on pragmas, a `Justification` on `[SuppressMessage]`, and review for any change to `NoWarn` or the shared config. Analyzer packages count as build inputs, pinned and upgraded deliberately.

code

xml · 14 lines
xml
<Project>
  <PropertyGroup>
    <!-- Same rule set on every machine; raised on purpose, never by an SDK update -->
    <AnalysisLevel>10.0-recommended</AnalysisLevel>
    <EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
    <Nullable>enable</Nullable>
    <!-- Nullable warnings fail every build, local and CI -->
    <WarningsAsErrors>$(WarningsAsErrors);nullable</WarningsAsErrors>
  </PropertyGroup>
  <!-- Every other warning fails the build only on the CI server -->
  <PropertyGroup Condition="'$(ContinuousIntegrationBuild)' == 'true'">
    <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
  </PropertyGroup>
</Project>

go deeper

for a junior

Know that a team can make warnings fail the build and can set analyzer rules for every project from one file at the repository root.

for a middle

Explain how Directory.Build.props and a shared .editorconfig or .globalconfig spread the policy, and what pinning AnalysisLevel buys.

for a senior

Show that you can roll strictness out without breaking the team: measure, ratchet per project, bridge with WarningsNotAsErrors, and spot suppressions that hide real findings.

for a principal

Own the trade-offs: errors locally versus only in CI, pinned versus latest rules, how strict the mode is, who reviews suppressions, and how the policy evolves with each retarget.

## The decisions a lead owns Turning on stricter builds in a large solution is less about one property than about a set of decisions that have to fit together. For a 40-project solution moving to warnings as errors, a shared configuration and a newer `AnalysisLevel`, the lead has to decide: - **where** the policy lives, so projects do not drift apart; - **which rules** are enforced, and how that set changes over time; - **where** warnings fail the build: every machine, or only continuous integration; - **how** the existing warnings are paid down without blanket suppression; - **what** counts as an acceptable suppression, and who reviews it. None of these has a single right answer; each trades developer friction against the risk of findings slipping through. ## One place for the policy MSBuild imports the nearest `Directory.Build.props` it finds walking up from each project, so one file at the repository root reaches every project without a closer one, and properties such as `AnalysisLevel`, `Nullable`, `WarningsAsErrors` and `EnforceCodeStyleInBuild` are set once. Rule severities belong in one root `.editorconfig` or a `.globalconfig` (which applies to every project in its folder tree at `global_level` 100), with narrow overrides for tests. Third-party analyzer packages are **build inputs**: a version bump can add rules exactly like an SDK update, so they are pinned and upgraded in their own change. Changes to these files deserve code-owner review, because one line can relax a rule for all 40 projects. ## Which rules, and how they change `AnalysisLevel` left at its default follows the target framework, and `latest` follows the SDK. A pinned compound value such as `10.0-recommended` freezes the CA rule set and mode until someone raises it. The trade-off: | Choice | Benefit | Cost | |---|---|---| | Default or `latest` | new rules arrive automatically | a retarget or SDK update can break a strict build for reasons unrelated to the change | | Pinned version and mode | predictable builds; raises are planned work | someone must own the raise, or the rule set ages | Pinning suits a team that enforces warnings as errors, and it pairs naturally with a planned raise at each retarget. The mode is a second dial: `Recommended` is a common middle ground, `All` usually needs many opt-outs, and per-category properties such as `AnalysisModeSecurity` let a team be stricter where it matters most. ## Where warnings fail the build `TreatWarningsAsErrors` everywhere means nobody meets a surprise in the pipeline, but half-finished local work fails to compile and developers are tempted to suppress first and think later. Enforcing only in CI, by conditioning the property on `ContinuousIntegrationBuild` (which the pipeline passes as `-p:ContinuousIntegrationBuild=true`), keeps local builds fluid but turns some pushes red. A common compromise is a short list of ids that are errors everywhere through `WarningsAsErrors`, with the rest enforced in CI. The list is appended to `$(WarningsAsErrors)`, because the SDK already places `NU1605` there. ## Rolling it out without blanket suppression A big-bang switch on 40 projects produces hundreds of errors and a flood of hasty suppressions. A ratchet works better: 1. Measure: build once with the new `AnalysisLevel` and record the count per diagnostic id and per project, for example from the compiler's SARIF output via the `ErrorLog` property. 2. Turn strictness on for the projects that are already clean, and for all new projects. 3. Give each remaining project a `WarningsNotAsErrors` list of the ids it still violates, with an owner, and allow the list only to shrink. 4. Fix in batches by rule, starting with rules that flag real defects rather than style. 5. Raise `AnalysisLevel` or the mode again only when the previous step is done. ## Suppression rules Suppressions are where a strict policy quietly erodes, because every suppressed diagnostic is never reported and so can never fail the build. Rules that hold up: - `#pragma warning disable` always names ids, has a matching `restore`, and carries a comment; - `[SuppressMessage]` always has a `Justification`; for trim warnings, `[UnconditionalSuppressMessage]`; - a severity of `none` lives in a folder or project override with a stated reason, never in the root file; - `NoWarn` is reserved for ids a project rejects outright, and any change to it is reviewed; - the count of suppressions is visible, so a rise is noticed. The policy succeeds when a new warning is cheaper to fix than to hide, and fails when the reverse is true; the lead's job is to keep the balance on the right side.

  • Would you make warnings errors on developer machines too?
    It depends on the team. Errors everywhere remove pipeline surprises but block half-finished local work and invite reflex suppressions; CI-only keeps local builds fluid at the cost of some red pushes. I would make a short list, such as nullable warnings, errors everywhere and enforce the rest in CI, then revisit once the warning count is near zero.
  • How do you stop an analyzer package upgrade from breaking 40 builds at once?
    Treat the package like the SDK: pin its version centrally, upgrade it in a dedicated change, build the whole solution with it, and either fix the new findings or set their severity explicitly in the shared config before merging. The same applies to raising AnalysisLevel.
  • How would you keep the suppression count from creeping up?
    Make suppressions visible and reviewed: require ids and restores on pragmas, a Justification on every [SuppressMessage], code-owner review on NoWarn and shared configuration, and a periodic report of suppression counts per project so a rise prompts a conversation.

  • Leaving AnalysisLevel at latest is always fine because new rules only add value.
  • Setting NoWarn for every new id is an acceptable way to turn strict builds on.
  • Warnings as errors can be enabled on all 40 projects in one change without measuring first.
  • Analyzer package versions do not matter as long as the SDK is pinned.
  • Suppressions need no review because the build is still green.