This repository uses local .NET tools and Husky.Net to keep staged C# files formatted before each commit.
When you run dotnet restore APITemplate.slnx or dotnet build APITemplate.slnx, MSBuild runs a target from the repository root Directory.Build.targets that:
- Restores local tools from
.config/dotnet-tools.json - Installs Git hooks with
dotnet husky install
The target is incremental:
- it reruns when
.config/dotnet-tools.jsonchanges - it reruns when
.husky/pre-commitdoes not exist
The pre-commit hook runs dotnet husky run --group pre-commit.
Husky.Net then:
- formats staged
*.csfiles withCSharpier - adds the formatted files back to the Git index
- blocks the commit if formatting fails
Format the repository:
dotnet csharpier format .Check formatting without changing files:
dotnet csharpier check .Run the configured Husky tasks manually:
dotnet husky run --group pre-commitRestore local tools manually:
dotnet tool restoreCI should not install local Git hooks. Disable the MSBuild target by setting either of these environment variables to 0:
RESTORE_TOOLSHUSKY
Example:
$env:RESTORE_TOOLS = "0"
dotnet build APITemplate.slnxIf the hook is missing or outdated:
dotnet tool restore
dotnet husky installIf you need to bypass the hook for an exceptional case:
git commit --no-verify