In a .NET 10 project, what do AnalysisLevel values such as latest, 8.0 and 10.0-recommended decide, and how does AnalysisMode interact with them?
answer
- which release's CA rules
- version prefix, mode suffix
- default follows the target framework
- suffix beats AnalysisMode
basics
~20 sAnalysisLevel picks which .NET release's CA rule set and default severities apply; an optional suffix such as -recommended picks the analysis mode. AnalysisMode sets the mode on its own, but an AnalysisLevel suffix takes precedence over it.
solid answer
~40 s`AnalysisLevel` chooses the code quality rule set by release: `8.0` means the rules and default severities .NET 8 shipped, `latest` means the newest release the SDK knows (10.0 on the .NET 10 SDK) and `preview` the next one. Unset, it follows the target framework: `latest` for net10.0, `8.0` for net8.0. A suffix chooses the **mode**: `none`, `default`, `minimum`, `recommended` or `all`, each a stricter set of rules raised to warnings. `AnalysisMode` sets the same modes separately, and when both are present the suffix wins. Pinning a number such as `10.0-recommended` keeps the set fixed until the team raises it. The SDK applies a mode through a global config file at `global_level` -100, so a team's own per-rule entries in `.editorconfig` or `.globalconfig` override it.
code
xml · 9 lines<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<!-- .NET 10 rule set, Recommended mode; stays fixed across SDK updates -->
<AnalysisLevel>10.0-recommended</AnalysisLevel>
<!-- Ignored for the main rule set: the AnalysisLevel suffix wins -->
<AnalysisMode>None</AnalysisMode>
<!-- Security category only: every rule as a warning -->
<AnalysisModeSecurity>All</AnalysisModeSecurity>
</PropertyGroup>go deeper
Know that AnalysisLevel picks a release's set of CA rules and that a suffix such as -recommended makes analysis stricter. Recall that net10.0 projects run the built-in analyzers by default.
Explain the version and mode parts, list the five modes in order, and say what the default is for net10.0 versus an older .NET target.
Show you can predict a project's effective rules: the default that follows the target framework, the suffix that beats AnalysisMode, per-category overrides, and the -100 global_level that lets team entries win.
Decide whether the repository pins a level and mode, how often it raises them, and how a raise is reviewed so new rules land as planned work rather than surprise red builds.
## Two questions, two properties The built-in **code quality analyzers** (the `CA` rules) ship with the .NET SDK, and two questions decide what they report in a build: - **Which release's rules?** Every .NET release adds rules and sometimes changes default severities. `AnalysisLevel` picks the release. - **How aggressive?** Most rules are off or at suggestion severity by default. The **analysis mode** picks how many of them are raised to build warnings. `AnalysisLevel` can answer both at once with a compound value, `<version>-<mode>`; `AnalysisMode` answers only the second. ## The version part | Value | Meaning on the .NET 10 SDK | |---|---| | `latest` | the newest released rule set, mapped to 10.0 | | `preview` | the next rule set, mapped to 11.0; it also raises an unset `WarningLevel` to 9999 | | `10.0` or `10` | the rules and default severities .NET 10 shipped | | `8.0` or `8` | the .NET 8 set, even though newer rules exist | | `none` | maps to 4.0, below the first rule set, which leaves the analyzers off unless `EnableNETAnalyzers` is set | When `AnalysisLevel` is left out, the SDK fills it in from the target framework: `latest` when the target is the SDK's newest framework (net10.0 here), otherwise that framework's version, so a net8.0 project gets `8.0` and a net9.0 project `9.0`. .NET Framework and netstandard2.0 projects get no value at all, and their `EnableNETAnalyzers` evaluates to `false`, so the CA rules do not run unless the project turns them on. A numeric level pins only the CA rules; the compiler's warning waves keep following the target framework. ## The mode part The modes, from the fewest warnings to the most, are: 1. `None`: every rule disabled; opt in rule by rule. 2. `Default`: the small set enabled as warnings in each release, such as `CA2200`, plus suggestions in the IDE. 3. `Minimum`: adds rules highly recommended for build enforcement; 92 rules are warnings in the SDK's 10.0 file. 4. `Recommended`: more again; 145 warnings in the 10.0 file. 5. `All`: every rule as a warning, 280 in the 10.0 file, except a few legacy and code-metrics rules that must be enabled by id. The SDK implements each combination as a file named like `analysislevel_10_recommended.globalconfig` in its analyzers folder, and the file declares `global_level = -100`. That low level is the point: any `dotnet_diagnostic.<id>.severity` entry in the team's own `.editorconfig` or `.globalconfig` overrides what the mode decided for that rule. ## How the two properties combine - **The suffix wins.** On the .NET SDK 10.0.401, `AnalysisLevel` set to `latest-recommended` together with `AnalysisMode` set to `None` still raised `CA1050` and `CA1805` to warnings: the MSBuild targets read the suffix first and fall back to `AnalysisMode` only when there is none. - **Per category.** `AnalysisLevel<Category>` and `AnalysisMode<Category>` (for example `AnalysisModeSecurity` set to `All`) tune one rule category without changing the rest. - **Code style too.** With `EnforceCodeStyleInBuild` set to `true`, the analysis level and mode also govern the `IDE` rules on build. - **Warnings as errors.** When `CodeAnalysisTreatWarningsAsErrors` is `true`, the SDK switches to the `_warnaserror` variant of the same file, so the mode's warnings arrive as errors. ## Why a team pins a number Left at its default, the rule set moves when a project is retargeted, and `latest` moves with each new SDK major version. Each move can add warnings or change default severities, which under warnings-as-errors means a red build that has nothing to do with the change in the pull request. A pinned value such as `10.0-recommended` keeps the set stable across SDK patches and retargets; the docs note that bug fixes to existing rules still arrive. The team then raises the number deliberately, in a change that fixes or triages what the new rules report. ## Checking what a project really gets Because several properties feed the result, it pays to ask MSBuild instead of guessing. `dotnet msbuild -getProperty:AnalysisLevel -getProperty:EffectiveAnalysisLevel -getProperty:WarningLevel` on a plain net10.0 project with the .NET 10 SDK printed `latest`, `10.0` and `10`; the same project evaluated with `TargetFramework` set to net8.0 printed `8.0`, `8.0` and `8`. The effective level names the rule-set file, and the mode names its suffix, so `10.0` plus `Recommended` means the rules listed in `analysislevel_10_recommended.globalconfig`.
- Why does a net8.0 project built with the .NET 10 SDK not get the .NET 10 rules?The SDK defaults AnalysisLevel to latest only when the target is its newest framework; for older .NET targets it uses the target framework's version, so net8.0 evaluates to 8.0. Setting AnalysisLevel to latest or a number overrides that.
- How do you enable every Security rule while keeping the rest at the default mode?Set AnalysisModeSecurity to All, or AnalysisLevelSecurity to a compound value such as latest-all. Per-category properties default to the main AnalysisLevel and AnalysisMode when absent, so the other categories keep their mode.
- Can you turn off one rule that the Recommended mode raised to a warning?Yes. The SDK applies the mode through a global config file at global_level -100, so dotnet_diagnostic.<id>.severity = none or suggestion in the team's .editorconfig or .globalconfig overrides it for that rule.
- AnalysisLevel defaults to latest for every project that targets .NET 5 or later.
- When AnalysisLevel and AnalysisMode disagree, AnalysisMode wins because it is more specific.
- A numeric AnalysisLevel also pins the compiler's warning waves.
- AnalysisMode All enables every rule with no exceptions.
- A pinned AnalysisLevel stops even bug fixes to existing rules.
Assumes the .NET 10 SDK (10.0.401), where latest maps to the 10.0 rule set and preview to 11.0, and Minimum, Recommended and All raise 92, 145 and 280 rules to warnings.