CodeEnforcer.Analyzers 0.1.0-ci.10

This is a prerelease version of CodeEnforcer.Analyzers.
dotnet add package CodeEnforcer.Analyzers --version 0.1.0-ci.10
                    
NuGet\Install-Package CodeEnforcer.Analyzers -Version 0.1.0-ci.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CodeEnforcer.Analyzers" Version="0.1.0-ci.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CodeEnforcer.Analyzers" Version="0.1.0-ci.10" />
                    
Directory.Packages.props
<PackageReference Include="CodeEnforcer.Analyzers" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CodeEnforcer.Analyzers --version 0.1.0-ci.10
                    
#r "nuget: CodeEnforcer.Analyzers, 0.1.0-ci.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CodeEnforcer.Analyzers@0.1.0-ci.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CodeEnforcer.Analyzers&version=0.1.0-ci.10&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CodeEnforcer.Analyzers&version=0.1.0-ci.10&prerelease
                    
Install as a Cake Tool

CodeEnforcer

CI CodeEnforcer NuGet CodeEnforcer downloads Analyzers NuGet Analyzers downloads .NET

CodeEnforcer is a repository-local C# structure gate. It scans tracked files and fails when file length, folder size, project-root folder size, or one-file-folder patterns cross enforced limits.

The CLI is designed for CI and pre-commit usage: exclusions are centralized in .config/code-enforcer/justifications.json so structural debt is visible in review. The repository also ships CodeEnforcer.Analyzers, a Roslyn analyzer package for compiler and IDE feedback.

What You Get

  • A code-enforcer .NET tool for repository-wide checks.
  • A CodeEnforcer.Analyzers package for compile-time and IDE feedback.
  • A one-command init flow that writes config files and installs the pre-commit hook.
  • CLI CRUD for exceptions and justifications, so teams do not need to hand-edit JSON.
  • Shared CLI/analyzer rule IDs: CE0001 through CE0004.
  • A commit-time CLI-only anti-gaming rule: CE0005.

Install

Install the CLI tool:

dotnet tool install --global CodeEnforcer --prerelease

Add the analyzer to a project:

dotnet add package CodeEnforcer.Analyzers --prerelease

Rules

  • CE0001: A tracked C# file exceeds maxLinesSoft and is not listed in justifications.json.
  • CE0002: A tracked C# file exceeds maxLinesHard and its exclusion has no non-empty justification.
  • CE0003: A folder contains more tracked C# files than maxFilesPerDir.
  • CE0004: A folder containing a .csproj contains more tracked C# files than maxFilesPerRootDir.
  • CE0005: The repository contains more than two folders that have exactly one tracked C# file and no other tracked files. This is CLI-only because it needs git ls-files.

Generated and build-output files are skipped:

  • bin/**
  • obj/**
  • *.g.cs
  • *.Designer.cs

Run

From a repository that contains .config/code-enforcer/code-enforcer.json:

code-enforcer

Or explicitly:

code-enforcer check

Run from this source checkout:

dotnet run --project src/CodeEnforcer -- check --root . --config .config/code-enforcer/code-enforcer.json

Run the complete verification gate:

./scripts/verify.ps1

Build the .NET tool

./scripts/build-tool.ps1
dotnet tool install --global --add-source ./artifacts/packages CodeEnforcer

The installed command is:

code-enforcer

Initialize A Repository

Create the default config files and install the git pre-commit hook:

code-enforcer init

This creates:

  • .config/code-enforcer/code-enforcer.json
  • .config/code-enforcer/justifications.json
  • .githooks/pre-commit

It also runs git config core.hooksPath .githooks. Existing files are kept unless --force is supplied.

The same build script also creates CodeEnforcer.Analyzers.0.1.0.nupkg.

Roslyn Analyzer

Install the analyzer package into a consuming project:

dotnet add package CodeEnforcer.Analyzers --source ./artifacts/packages

Configure analyzer limits and exclusions in .editorconfig. See analyzer for install, configuration, and CLI differences.

Configuration

CodeEnforcer walks from the current directory to parent directories until it finds:

.config/code-enforcer/code-enforcer.json

The same folder must also contain:

.config/code-enforcer/justifications.json

See configuration for CLI schema details and examples.

Manage Justifications

Use the CLI to create, read, update, and delete entries in .config/code-enforcer/justifications.json:

code-enforcer justifications add --type file --path src/App/Large.cs --justification "Scheduled for split"
code-enforcer justifications list
code-enforcer justifications show --type file --path src/App/Large.cs
code-enforcer justifications update --type file --path src/App/Large.cs --justification "Split after adapter cleanup"
code-enforcer justifications remove --type file --path src/App/Large.cs

exceptions is an alias for justifications, so code-enforcer exceptions add ... works the same way.

Development

See development for local verification, git hook setup, and package build instructions.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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
0.1.0-ci.10 80 6/12/2026
0.1.0-ci.9 74 6/12/2026
0.1.0-ci.8 70 6/12/2026
0.1.0-ci.7 66 6/12/2026
0.1.0-ci.6 70 6/12/2026
0.1.0-ci.5 70 6/12/2026