agentleFS
SebastienDegodezSebastienDegodez/copilot-instructions/skills/setup-husky-dotnet/SKILL.md

setup-husky-dotnet

Skill199 starsChanged 5 days agoApache-2.0View on GitHub

Use when configuring Git hooks in .NET projects before team commits occur, to enforce commit message standards and code formatting automatically

The file

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When NOT to use: If .NET SDK unavailable, manually configure git hooks instead.

    line 17
  2. Distinctive:

    If ANY fails, STOP — install missing tools before proceeding.

    line 59

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Husky Setup for .NET Projects (dotnet tool)

Install and configure Husky Git hooks for .NET projects using dotnet tool (not npm). Enforces conventional commit messages and code formatting via git hooks.

When to Use

  • Setting up Git governance in .NET projects (new or existing)
  • Enforcing team commit standards before they reach main branch
  • Preventing unformatted code or invalid messages in version control
  • REQUIRED BEFORE: First commits when governance is non-negotiable

When NOT to use: If .NET SDK unavailable, manually configure git hooks instead.

Critical: .NET Tool Only

Husky (dotnet tool) is pure .NET. Your environment needs:

  • .NET SDK 10.0+
  • dotnet CLI available in PATH
  • git initialized

No Node.js, npm, or JavaScript tools required.

Core Pattern

1. Create tool-manifest.json + install Husky dotnet tool
2. Enable git hook infrastructure with dotnet husky install
3. Create commit-msg hook that validates message format
4. Create pre-commit hook that runs dotnet-format
5. MANDATORY: Test hooks with both valid + invalid commits
6. Commit .husky/ and task-runner.json to git

Quick Reference

StepCommandCreatesPurpose
Setupdotnet new tool-manifest.config/dotnet-tools.jsonTool tracking
Installdotnet tool install huskyAdds Husky to toolingMakes Husky available
Enabledotnet husky install.husky/ directoryPrepares git hook system
Msg Hookdotnet husky add commit-msgHook fileValidates commit format
Pre-Commitdotnet husky add pre-commitHook fileRuns formatting before commit

Implementation

Prerequisites - VERIFY FIRST

CRITICAL - Run these commands NOW:

dotnet --version   # Must return 6.0+
git --version      # Must work
dotnet-format --version  # Must be installed

If ANY fails, STOP — install missing tools before proceeding.

Required software:

  • .NET SDK 6.0+ (download from dotnet.microsoft.com)
  • Git repository initialized (git init if needed)
  • dotnet-format global: dotnet tool install -g dotnet.format

Installation Steps

Step 1: Create tool manifest + Install Husky (in project root)

cd your-dotnet-project

# Create reproducible tool manifest
dotnet new tool-manifest

# Install Husky as .NET tool
dotnet tool install husky

# Initialize git hook system
dotnet husky install

Verify: ls -la .husky/ shows directory with subdirectories.

Step 2: Setup hooks and config

Copy the C# validator to your project:

mkdir -p .husky/csx
cp ./commit-lint.csx .husky/csx/commit-lint.csx

Copy task-runner.json from skill assets/ to project root:

cp ./task-runner.json.example ./task-runner.json

Note: task-runner.json.example contains BOTH commit-msg and pre-commit tasks. Use as-is.

Create both hooks:

dotnet husky add commit-msg -c "dotnet husky run --name commit-message-linter"
dotnet husky add pre-commit -c "dotnet husky run --name dotnet-format"

Done! Both hooks are now configured.

Step 3: MANDATORY - Test hooks

⚠️ DON'T SKIP TESTING

# Create safe test branch (NEVER test on main)
git checkout -b test-hooks-validation

# Test 1: Invalid message MUST be rejected
echo "dummy" > test.cs
git add test.cs
git commit -m "bad message"  # Should FAIL
echo $?  # Must be 1 (failure)

# Test 2: Valid message MUST be accepted
git commit --amend -m "feat(test): verify hooks working"  # Should SUCCEED
echo $?  # Must be 0 (success)

# Cleanup
git checkout main
git branch -D test-hooks-validation

Both tests must pass before proceeding.

Files in Skill Directories

scripts/ — Reusable code:

  • commit-lint.csx — C# validator for conventional commits (copy to .husky/csx/)

assets/ — Configuration examples:

  • task-runner.json.example — Hook task configuration (copy to project root)

Common Mistakes

MistakePrevention
dotnet --version failsInstall .NET 6.0+, verify PATH before setup
.husky/ not createdRun dotnet husky install in project root
Hooks don't executeCheck: ls -la .husky/commit-msg exists
Tests show git succeeds with invalid messageHooks never ran. Check task-runner.json syntax.
dotnet-format not found during pre-commitInstall: dotnet tool install -g dotnet.format

What Gets Committed to Git

MUST commit:

  • .husky/ directory (all files)
  • task-runner.json (hook configuration)
  • .config/dotnet-tools.json (tool version lock)

DO NOT commit:

  • Nothing else (all tools managed via dotnet-tools.json)

Result: Team clones repo → dotnet tool restore → hooks active immediately.

CI/CD Integration

Husky runs on developer machines only, NOT in CI/CD (by design).

CI must validate separately:

dotnet-format --verify-no-changes

Troubleshooting

See troubleshooting.md in this skill for:

  • Full diagnostic checklist if hooks not running
  • task-runner.json configuration issues
  • Monorepo setup
  • Problems after merge conflicts
  • Windows/Mac/Linux differences

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.