.NET Wrangler
Roslyn analyzers that put guardrails on .NET code.
Wrangler encourages explicit null contracts, meaningful test failures, and reviewable warning suppressions.
Read the documentation site or browse the guides below.
Start here
From the folder containing your C# project's .csproj, install the DotNetWrangler.Analyzers NuGet prerelease:
dotnet add package DotNetWrangler.Analyzers --prerelease
Run dotnet build to see any Wrangler diagnostics. No source checkout is needed.
- Getting started: install in Visual Studio, check compiler compatibility, and try a diagnostic.
- Configuration: choose severities and enable the optional pragma policies.
- Suppressing a diagnostic: document intentional exceptions without disabling a rule project-wide.
- Analyzer catalog: find a rule's explanation, examples, and code-fix availability.
Analyzer catalog
| ID | Description | Default severity | Code fix |
|---|---|---|---|
| WRANGLER0001 | Handle null explicitly instead of overriding nullable analysis with !. |
Warning | No |
| WRANGLER0002 | Avoid fabricating non-null values with null! or reference-type default!. |
Warning | No |
| WRANGLER0003 | Prefer a framework-specific not-null assertion in tests. | Warning | No |
| WRANGLER0004 | Document explicit pragma suppression IDs and rule titles. | Disabled (opt-in warning) | When titles are available |
| WRANGLER0005 | Require an explicit justification for pragma suppressions. | Disabled (opt-in warning) | No |
The three null-forgiving rules are alternatives, not three diagnostics on every !. WRANGLER0001 explains which rule takes precedence. Valid uses can still receive a diagnostic; use a scoped suppression with a reason for intentional exceptions.
Rule details
WRANGLER0001
Null-forgiving operator hides a possible null value: explicit null handling and precedence among the null-forgiving rules.
WRANGLER0002
Null-forgiving operator fabricates a non-null value: meaningful initialization, nullable contracts, and intentional null-input tests.
WRANGLER0003
Use a not-null assertion instead of the null-forgiving operator in tests: supported frameworks, assertion recommendations, and async/nullable limitations.
WRANGLER0004
Document suppressed diagnostic IDs and titles: single/multiple-ID formats, external title catalogs, validation modes, and code-fix limits.
WRANGLER0005
Justify warning suppressions: accepted justification locations, field syntax, and policy scope.
Configuration
Every rule supports standard .editorconfig severity settings, including none, and scoped pragma suppression. WRANGLER0004 and WRANGLER0005 are independent opt-in policies.
See configuration examples and suppression guidance.
Related tools
- Nullable.Extended.Analyzer reports
!without a// !justification comment. - Meziantou.Analyzer has an opt-in rule for
null!/default!. - The .NET SDK's IDE analyzers report
!that the compiler doesn't need and offer to remove it. - StyleCop SA1404 requires justifications on
SuppressMessageattributes, not pragma title/reason comments. The related pragma proposal DotNetAnalyzers/StyleCopAnalyzers#3403 motivated similar discussion. - The SDK's IDE0079 finds unnecessary suppressions; WRANGLER0004/WRANGLER0005 document the suppressions that remain.
Projects
src/Wrangler.Analyzerscontains the diagnostic analyzers and targets .NET Standard 2.0.src/Wrangler.CodeFixescontains the code fix providers and targets .NET Standard 2.0.src/Wrangler.Packagepacks both assemblies into theDotNetWrangler.AnalyzersNuGet package.tests/Wrangler.Testscontains analyzer and code-fix tests.
Build and test
Repository development requires the .NET 11 SDK selected by global.json and the .NET 8 runtime for tests. Shipped analyzers and code fixes use the Roslyn 5.0 API baseline so consumers can use .NET 10 compiler hosts; see compiler compatibility.
dotnet test DotNetWrangler.slnx -warnaserror
CI treats compiler, enabled analyzer, and MSBuild warnings as errors during restore, build, test, and pack. The repository enables RS1015 to require diagnostic help links; warnings-as-errors does not enable other disabled rules.
Roslyn minor/major upgrades and composition major upgrades are excluded from routine Dependabot updates because they can raise the minimum host version. Change the baseline deliberately, together with compatibility documentation and compiler-host checks.
Release
The publish workflow tests the solution, packs it, and publishes to nuget.org through trusted publishing.
- Pushing a
vMAJOR.MINOR.PATCH[-prerelease]tag publishes exactly that version. Only tags without a suffix publish stable versions. - The nightly run at 10:05 UTC publishes from
mainonly if that commit has not already published. It takes the highest tagged version, increments its patch if it is stable, and appends-beta.<run number>. After the first tagged beta, use a different suffix (for example,-rc.1) for manual prereleases to avoid colliding with nightly versions.
Verify a package locally before releasing:
dotnet pack src/Wrangler.Package/Wrangler.Package.csproj -c Release -o artifacts -p:Version=0.0.0-local
With the .NET 10.0.1xx and .NET 11.0.1xx SDKs installed, verify the package in both compiler hosts:
pwsh -File .github\scripts\verify-analyzer-package.ps1 -PackageDirectory artifacts -PackageVersion 0.0.0-local
The script selects SDKs independently of this repository's global.json and cleans up its temporary consumers. Pass -SdkVersions when invoking it from PowerShell to select other installed SDK feature bands.
See maintaining the documentation to build, preview, customize, and publish the DocFX site.
License
.NET Wrangler is licensed under the Apache-2.0 license.