CodeEnforcer 0.1.0-ci.10

This is a prerelease version of CodeEnforcer.
dotnet tool install --global CodeEnforcer --version 0.1.0-ci.10
                    
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest
                    
if you are setting up this repo
dotnet tool install --local CodeEnforcer --version 0.1.0-ci.10
                    
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=CodeEnforcer&version=0.1.0-ci.10&prerelease
                    
nuke :add-package CodeEnforcer --version 0.1.0-ci.10
                    

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.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last Updated
0.1.0-ci.10 136 6/12/2026
0.1.0-ci.9 97 6/12/2026
0.1.0-ci.8 346 6/12/2026
0.1.0-ci.7 71 6/12/2026
0.1.0-ci.6 87 6/12/2026
0.1.0-ci.5 84 6/12/2026