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
In this repository5 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- creating-dotnet-mcp-serversSkill
- generate-microcks-openapi-samplesSkill
- migrating-prompts-to-skillsSkill
- skill-creatorSkill
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
- Distinctive: line 17
When NOT to use: If .NET SDK unavailable, manually configure git hooks instead.
- Distinctive: line 59
If ANY fails, STOP — install missing tools before proceeding.
≈ “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.
Files
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+dotnetCLI available in PATHgitinitialized
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 gitQuick Reference
| Step | Command | Creates | Purpose |
| Setup | dotnet new tool-manifest | .config/dotnet-tools.json | Tool tracking |
| Install | dotnet tool install husky | Adds Husky to tooling | Makes Husky available |
| Enable | dotnet husky install | .husky/ directory | Prepares git hook system |
| Msg Hook | dotnet husky add commit-msg | Hook file | Validates commit format |
| Pre-Commit | dotnet husky add pre-commit | Hook file | Runs 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 installedIf ANY fails, STOP — install missing tools before proceeding.
Required software:
- .NET SDK 6.0+ (download from dotnet.microsoft.com)
- Git repository initialized (
git initif 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 installVerify: 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.csxCopy task-runner.json from skill assets/ to project root:
cp ./task-runner.json.example ./task-runner.jsonNote: 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-validationBoth 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
| Mistake | Prevention |
dotnet --version fails | Install .NET 6.0+, verify PATH before setup |
.husky/ not created | Run dotnet husky install in project root |
| Hooks don't execute | Check: ls -la .husky/commit-msg exists |
| Tests show git succeeds with invalid message | Hooks never ran. Check task-runner.json syntax. |
dotnet-format not found during pre-commit | Install: 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-changesTroubleshooting
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
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
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.

