CodeEnforcer 0.1.0-ci.10
dotnet tool install --global CodeEnforcer --version 0.1.0-ci.10
dotnet new tool-manifest
dotnet tool install --local CodeEnforcer --version 0.1.0-ci.10
#tool dotnet:?package=CodeEnforcer&version=0.1.0-ci.10&prerelease
nuke :add-package CodeEnforcer --version 0.1.0-ci.10
CodeEnforcer
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.Analyzerspackage for compile-time and IDE feedback. - A one-command
initflow 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:
CE0001throughCE0004. - 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 exceedsmaxLinesSoftand is not listed injustifications.json.CE0002: A tracked C# file exceedsmaxLinesHardand its exclusion has no non-empty justification.CE0003: A folder contains more tracked C# files thanmaxFilesPerDir.CE0004: A folder containing a.csprojcontains more tracked C# files thanmaxFilesPerRootDir.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 needsgit 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 | Versions 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. |
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 |