Digitals.Analyzers
0.5.0
See the version list below for details.
dotnet add package Digitals.Analyzers --version 0.5.0
NuGet\Install-Package Digitals.Analyzers -Version 0.5.0
<PackageReference Include="Digitals.Analyzers" Version="0.5.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="Digitals.Analyzers" Version="0.5.0" />
<PackageReference Include="Digitals.Analyzers"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add Digitals.Analyzers --version 0.5.0
#r "nuget: Digitals.Analyzers, 0.5.0"
#:package Digitals.Analyzers@0.5.0
#addin nuget:?package=Digitals.Analyzers&version=0.5.0
#tool nuget:?package=Digitals.Analyzers&version=0.5.0
Digitals.Analyzers
Single NuGet package that brings the full org analyzer set plus the shared severity policy. Reference one package instead of four, and severity/banned-API policy comes along centrally.
What it brings
| Package | Purpose |
|---|---|
| SonarAnalyzer.CSharp | Quality and bug rules |
| Roslynator.Analyzers | Refactoring/style rules |
| Roslynator.Formatting.Analyzers | Formatting rules |
| Microsoft.VisualStudio.Threading.Analyzers | Async/threading rules (VSTHRD) |
| Microsoft.CodeAnalysis.BannedApiAnalyzers | Enforces BannedSymbols.txt (RS0030) |
Plus config injected automatically via auto-imported build/Digitals.Analyzers.props / .targets:
Digitals.Analyzers.globalconfig— the full org style + severity policy (formatting, idioms, naming rules, CA/S/RCS/VSTHRD severities), ported from the mastertemplates/dotnet/.editorconfig.Digitals.Analyzers.Tests.globalconfig— test-project relaxations (the old[**.Tests/**.cs]section). Injected only into projects whose name ends with.Tests— global configs cannot scope by path, so scoping is per project.BannedSymbols.txt— banned APIs (RS0030,warning; each repo decides escalation viaTreatWarningsAsErrors):DateTime.Now/UtcNow/TodayandDateTimeOffset.Now/UtcNow— injectTimeProviderinstead (TimeProvider.Systemin DI composition roots,FakeTimeProviderin tests). RS0030 is deliberately clock-only — see the custom rules below.analyzers/dotnet/cs/Digitals.Analyzers.CSharp.dll— custom org rules (warning), enforcing the org temporal-types rule:- DT00001 — any reference to
System.DateTime, including bare declarations (DateTime Foo { get; set; }) that a banned-symbol list cannot see. UseDateOnly(calendar date),TimeOnly(time of day),TimeSpan(duration) orDateTimeOffsetin UTC (instant);DateTimeis an interop-boundary exception carrying a#pragmawith a reason. - DT00002 —
DateTimeOffset.LocalDateTime/.DateTime, which silently reintroduceDateTime;.UtcDateTimeis the sanctioned boundary conversion. - DT00003 —
new HttpClient(); useIHttpClientFactory(AddHttpClient) — a client per call exhausts sockets. - DT00004 —
dynamic; resolve types at compile time (generics, DI, typed models). Not expressible as a banned symbol —dynamiccompiles toobjectplus an attribute. - DT00005 — xUnit test names must be
Method_Scenario_ExpectedResult(three PascalCase segments). Scoped by the[Fact]/[Theory]attribute, so it is inert outside test projects. - DT00006 (
suggestion) —double/floatmember or parameter whose name contains a money term (price,cost,fee, …); usedecimal. Name heuristic, IDE-only. - Own IDs on purpose: a boundary
#pragma warning disable DT00001never switches off the RS0030 ambient-clock ban in the same region.
- DT00001 — any reference to
The globalconfig also escalates shipped-pack rules that are off or info-only by default:
SYSLIB1045([GeneratedRegex]),CA2254(structured log templates),VSTHRD100(noasync void, pinned) aswarning;CA2100(raw SQL),CA1002/CA1819(read-only collection properties),CA1021(nooutparams),S109(magic numbers) as IDE-onlysuggestion.Digitals.Analyzers.targets— banned NuGet packages (DIGB001build error on a directPackageReference):Moq(use NSubstitute),FluentAssertions(use xUnit built-inAssert.*; v8+ requires a commercial license, frozen v7 gets no security backports),xunit/xunit.core(xUnit v2 — usexunit.v3),Newtonsoft.Json/Microsoft.AspNetCore.Mvc.NewtonsoftJson(useSystem.Text.Json),AutoMapper+ its DI extension (write explicit mapping; v15+ commercial license),EntityFramework(EF6 — useMicrosoft.EntityFrameworkCore),System.Data.SqlClient(useMicrosoft.Data.SqlClient),Microsoft.EntityFrameworkCore.Proxies(no lazy loading),NUnit/MSTest/MSTest.TestFramework(org framework is xunit.v3), and the v2-lineage xUnit integrationsTngTech.ArchUnitNET.xUnit/FsCheck.Xunit/Verify.Xunit/Microsoft.Playwright.Xunit(each has a v3-ID replacement). Per the org .NET test stack. Transitive dependencies are not visible to the check. Escape hatch, next to a comment explaining why:<DigitalsAllowBannedPackages>Moq</DigitalsAllowBannedPackages>
Usage
<PackageReference Include="Digitals.Analyzers">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Typically once in Directory.Build.props, replacing the individual analyzer references. Migrating an existing repo: step-by-step in docs/ADOPTION.md. The package is marked DevelopmentDependency, so PrivateAssets="all" is also the default NuGet applies on install — it prevents the analyzers from flowing further into your consumers.
Escape hatch
Legitimate banned-API sites exist (bootstrap logging before DI is built, EF migration defaults):
#pragma warning disable RS0030 // Serilog bootstrap, DI not built yet
Log.Information("Starting at {Now}", DateTimeOffset.UtcNow);
#pragma warning restore RS0030
Suppressions are grep-able and reviewable. If they multiply, that is signal.
Overriding a rule per repo
A repo-local .editorconfig always wins over the packaged globalconfig:
[*.cs]
dotnet_diagnostic.S1234.severity = none
What stays in each repo
Some things a global config cannot express — each repo keeps a thin .editorconfig with only:
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
[*.{props,csproj}]
indent_style = tab
indent_size = 4
tab_width = 4
[*.{cs,vb,cshtml}]
indent_style = tab
indent_size = 4
tab_width = 4
max_line_length = 120
plus any repo-specific path-scoped overrides (e.g. [**/Pages/**.cshtml.cs], [**/Migrations/**.cs]) — global configs have no path sections. A repo-local .editorconfig also always overrides the packaged policy, which is the per-rule opt-out mechanism.
And in Directory.Build.props (compiler switches, not editorconfig knobs):
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
EnforceCodeStyleInBuild is required for the IDExxxx style rules to fire in dotnet build at all.
Design notes
Verified in a real build (scratch consumer against the packed nupkg): RS0030 fires, Sonar/Roslynator/VSTHRD load, naming rules (IDE1006) fire from the globalconfig, and the
.Testsglobalconfig suppresses (e.g. S1186) only in test projects.Naming-rule build enforcement needs
dotnet_diagnostic.IDE1006.severity— the per-ruleseverityinsidedotnet_naming_rule.*is IDE-only. The master.editorconfigwas missing this; the packaged globalconfig has it.Test scoping is by project name (
*.Tests), not path glob. Rename conventions (.Tests.Unitetc.) need the condition inbuild/Digitals.Analyzers.propsextended.Meta-package mechanics. NuGet's default for dependencies is
exclude="build,analyzers"— a naive meta-package brings nothing. EveryPackageReferencein the csproj carriesPrivateAssets="none"to force analyzer assets to flow. Do not remove it.netstandard2.0, no multi-targeting. Analyzers run inside the compiler process, not the consuming app; consumer TFM is irrelevant. The only multi-targeting dimension that exists for analyzers is Roslyn version (analyzers/dotnet/roslyn4.x/cs/folders) — not needed until a custom rule requires a newer Roslyn API.C# only in practice. Sonar C# and Roslynator are C#-only; the threading and banned-API analyzers also cover VB. F# is out of scope entirely (different compiler, no Roslyn analyzers). In a VB or F# project this package silently does nothing.
Version pinning lives here. Bumping any analyzer means releasing a new version of this package. That is the point: one version to review, org-wide consistency.
Adding custom org rules
Custom Roslyn analyzers (org naming conventions, architecture rules) live in src/Digitals.Analyzers.CSharp (netstandard2.0, conservative Roslyn pin, DLL packed into analyzers/dotnet/cs/ — not lib/), tested in tests/Digitals.Analyzers.CSharp.Tests with Microsoft.CodeAnalysis.CSharp.Analyzer.Testing + xUnit v3. Adding a rule:
- Next
DT#####ID — stable prefix, never reuse or renumber IDs: they end up in suppressions and configs across repos. - Row in
AnalyzerReleases.Unshipped.md(RS2008 release tracking); move toShipped.mdwhen the version ships. - Severity line in the globalconfig (
warning— repos escalate viaTreatWarningsAsErrors). - Tests for the report cases, the clean cases, and the
#pragmaescape.
Simple naming/style rules are cheap (a day for the first including tests, hours after that). Avoid dataflow rules — Sonar already does them.
Releasing
Versioning is MinVer: the version comes from git v* tags, not the csproj. To release:
git tag v1.1.0
git push origin v1.1.0
.github/workflows/release.yml packs the tagged commit and pushes it to nuget.org, then opens a GitHub Release for the tag. Re-running the workflow on the same tag is a no-op (--skip-duplicate), because the tag fully determines the version.
Tags are the only thing that publishes. Pushes to main run .github/workflows/ci.yml, which tests and packs and attaches the .nupkg as a build artifact, but publishes nothing. For a local package to inspect or test against, just pack writes to artifacts/.
Publishing uses nuget.org Trusted Publishing — a short-lived OIDC-issued key, no long-lived API key in GitHub secrets. The policy on nuget.org is bound to this repo and to the release.yml filename, so renaming that workflow file breaks publishing until the policy is updated. The one secret required is NUGET_USER, the nuget.org profile name.
License
MIT — see LICENSE. The license covers this repository's own code: the globalconfigs, BannedSymbols.txt, the .targets banned-package check and the custom DT##### analyzer. The bundled third-party analyzers keep their own licenses and reach consumers as ordinary NuGet dependencies.
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.BannedApiAnalyzers (>= 3.3.4)
- Microsoft.VisualStudio.Threading.Analyzers (>= 17.14.15)
- Roslynator.Analyzers (>= 4.15.0)
- Roslynator.Formatting.Analyzers (>= 4.15.0)
- SonarAnalyzer.CSharp (>= 10.19.0.132793)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | |
|---|---|---|---|
| 1.1.0 | 109 | 11/3/2026 | |
| 1.0.1 | 142 | 11/2/2026 | |
| 1.0.0 | 120 | 10/31/2026 | |
| 0.12.0 | 128 | 10/31/2026 | |
| 0.11.0 | 1,156 | 10/18/2026 | |
| 0.10.3 | 168 | 9/29/2026 | |
| 0.10.2 | 216 | 9/29/2026 | |
| 0.10.1 | 421 | 9/23/2026 | |
| 0.10.0 | 138 | 9/23/2026 | |
| 0.9.0 | 138 | 9/23/2026 | |
| 0.8.0 | 175 | 9/21/2026 | |
| 0.7.2 | 158 | 9/19/2026 | |
| 0.7.1 | 139 | 9/19/2026 | |
| 0.7.0 | 136 | 9/19/2026 | |
| 0.6.0 | 583 | 8/31/2026 | |
| 0.5.1 | 323 | 8/26/2026 | |
| 0.5.0 | 186 | 8/20/2026 |