Skip to content

Repository files navigation

README banner

Personal set of rules, analyzers, and build defaults distributed as a NuGet package for .NET 10 C# projects.

Heavily based on Gérald Barré (@Meziantou)'s "Sharing coding style and Roslyn analyzers across projects" post and his CodingStandard repository.
This config contains rules changed and fine-tuned to my personal and work needs as well as preferences.

Usage

Add the NuGet package package to your project, and the configs will be automatically imported.
PrivateAssets="all" prevents the configuration package and its analyzer dependencies from becoming dependencies of a package you publish.

Direct package reference

<ItemGroup>
  <PackageReference Include="Kiruyuto.DotNet.Config" Version="2.4.14" PrivateAssets="all" />
</ItemGroup>

Central package management

<!-- Directory.Packages.props -->
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>

  <ItemGroup>
    <PackageVersion Include="Kiruyuto.DotNet.Config" Version="2.4.14" />
  </ItemGroup>
</Project>
<!-- Directory.Build.props -->
<Project>
  <ItemGroup>
    <PackageReference Include="Kiruyuto.DotNet.Config" PrivateAssets="all" />
  </ItemGroup>
</Project>

Applied defaults

The package imports the following policy into consuming projects:

Area Defaults
C# projects Enables nullable reference types, implicit usings, unsafe code, deterministic builds, and XML documentation. Adds global usings for System.Diagnostics.CodeAnalysis and System.Text, and disables CS1591.
Analysis Enables .NET analyzers and build-time code-style analysis using AnalysisLevel=10-all, strict compiler features, the packaged rule configurations, banned APIs, and analyzer timing reports.
Release and CI Release builds enable optimization and treat MSBuild warnings as errors. CI builds also set ContinuousIntegrationBuild and treat compiler and analyzer warnings as errors.
Package authoring Unless overridden, RepositoryType=git, EmbedUntrackedSources=true, and DebugType=embedded are applied to consumer projects. Embedded PDBs travel inside assemblies; no separate .snupkg is generated.

This is intentionally strict: warnings can fail Release and CI builds. 10-all pins the built-in analyzer profile to .NET 10.

Overriding defaults

NuGet package build props are imported before the body of a consuming project file. Defaults whose values are conditional on being empty can be preselected in Directory.Build.props. Any setting can be overridden later in the project file or in Directory.Build.targets; use Directory.Build.targets for repository-wide overrides that must win over this package's unconditional assignments.

Diagnostic severities and analyzer options can be customized in a project-owned .editorconfig or .globalconfig. Individual compiler or analyzer diagnostics can also be suppressed with the standard MSBuild warning properties.

Note

NuGet excludes package build imports while generating the restore graph, so this package intentionally does not distribute NuGet audit policy. This repository configures audit in its root Directory.Build.props; consuming repositories should configure their own policy there or in another repository-owned MSBuild file evaluated during restore.

Warning

This package bans EF Core's AddAsync and AddRangeAsync by default.
Projects that intentionally rely on async value generators, such as HiLo, can disable only those two bans using:

<Project>
  <PropertyGroup>
    <KiruyutoDotNetConfigEnableEntityFrameworkCoreAsyncAddBans>false</KiruyutoDotNetConfigEnableEntityFrameworkCoreAsyncAddBans>
  </PropertyGroup>
</Project>

The toggle also controls the corresponding VSTHRD103 exclusions. Setting it to false removes the async-add bans and stops excluding synchronous Add/AddRange, so VSTHRD103 may recommend their async counterparts in async methods.

Structure overview

Contributing

See CONTRIBUTING.md for guidelines, rule authoring, and local build/testing instructions.

About

A personal NuGet package containing rules and analyzers to share .NET code style and configuration across multiple projects

Resources

Contributing

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors