### Run Documentation Locally with Yarn Source: https://github.com/alirezanet/husky.net/blob/master/docs/contribution/README.md Use these commands to install dependencies and start the documentation development server using Yarn. ```cmd yarn install yarn dev ``` -------------------------------- ### Run Documentation Locally with npm Source: https://github.com/alirezanet/husky.net/blob/master/docs/contribution/README.md Use these commands to install dependencies and start the documentation development server using npm. ```cmd npm install npm run dev ``` -------------------------------- ### Setup Husky for Project Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/getting-started.md Initialize Husky.Net within your project after installation. Navigate to your project's root directory before running this command. ```shell cd dotnet husky install ``` -------------------------------- ### Install Husky.Net Locally Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/getting-started.md Install Husky.Net as a local tool for your project. This is the recommended approach. Ensure you are in your project's root directory. ```shell cd dotnet new tool-manifest dotnet tool install Husky ``` -------------------------------- ### Pre-commit Hook Example (.husky/pre-commit) Source: https://context7.com/alirezanet/husky.net/llms.txt Example of a .husky/pre-commit hook file that runs .NET Husky commands for pre-commit checks. ```bash #!/bin/sh . "$(dirname "$0")/_/husky.sh" dotnet husky run -v --group "pre-commit" ``` -------------------------------- ### Install Husky.Net Globally Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/getting-started.md Install Husky.Net as a global tool. This makes the commands available system-wide. Note that global installations may require the `dotnet` prefix for commands. ```shell dotnet tool install --global Husky ``` -------------------------------- ### Install Husky.Net as a Local Tool Source: https://context7.com/alirezanet/husky.net/llms.txt Install Husky.Net as a local tool in your .NET project for team-wide Git hooks automation. Ensure you are in your project root and have a tool manifest. ```bash # Navigate to your project root cd /path/to/your/project # Create a local tool manifest (if not exists) dotnet new tool-manifest # Install Husky as a local tool dotnet tool install Husky # Initialize Husky in your project dotnet husky install ``` -------------------------------- ### Automating Husky Installation in Project Files Source: https://context7.com/alirezanet/husky.net/llms.txt Attach Husky to your project file to automatically install hooks after `dotnet restore`. Use the `--force` option to overwrite existing configurations and `--ignore-submodule` to ignore submodules. ```bash # Automatically attach Husky to a project file dotnet husky attach src/MyProject/MyProject.csproj ``` ```bash # Attach with force (overwrite existing configuration) dotnet husky attach src/MyProject/MyProject.csproj --force ``` ```bash # Attach with submodule ignore option dotnet husky attach src/MyProject/MyProject.csproj --ignore-submodule ``` -------------------------------- ### npm Integration for Husky Installation Source: https://context7.com/alirezanet/husky.net/llms.txt Configure automatic Husky installation in package.json for projects using npm alongside .NET. This script runs during the 'prepare' lifecycle. ```json { "scripts": { "prepare": "dotnet tool restore && dotnet husky install" } } ``` -------------------------------- ### Manual Husky Attachment in .csproj Source: https://context7.com/alirezanet/husky.net/llms.txt Manually configure Husky installation within a .csproj file. This ensures Husky is installed after the restore target and before other build steps. ```xml ../../ ``` -------------------------------- ### npm package.json Alternative for Husky Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/automate.md For projects using npm, add this script to your package.json to automatically install Husky after 'npm install'. ```json "scripts": { "prepare": "dotnet tool restore && dotnet husky install" } ``` -------------------------------- ### Commit Message Hook Example (.husky/commit-msg) Source: https://context7.com/alirezanet/husky.net/llms.txt Example of a .husky/commit-msg hook file to validate commit messages using .NET Husky. ```bash #!/bin/sh . "$(dirname "$0")/_/husky.sh" dotnet husky run --name "commit-message-linter" --args "$1" echo echo Great work! echo ``` -------------------------------- ### Husky Ignore Submodule Install Message Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/submodules.md This message is displayed when the `--ignore-submodule` flag is used during Husky installation within a submodule, indicating that the installation is being skipped. ```text Submodule detected and [--ignore-when-submodule] is set, skipping install target ``` -------------------------------- ### Husky.NET Task Runner Configuration Example Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/task-runner.md This JSON defines various tasks for Husky.NET, including code formatting, commit message linting, build warnings, ESLint, Prettier, and a simple echo task. It demonstrates task grouping, conditional execution with `${staged}`, and platform-specific commands. ```json { "$schema": "https://alirezanet.github.io/Husky.Net/schema.json", "tasks": [ { "name": "dotnet-format", "group": "pre-commit", "command": "dotnet", "args": ["dotnet-format", "--include", "${staged}"], "include": ["**/*.cs", "**/*.vb"] }, { "name": "commit-message-linter", "command": "dotnet", "args": [ "husky", "exec", ".husky/csx/commit-lint.csx", "--args", "${args}" ] }, { "name": "warning-check", "command": "dotnet", "group": "pre-push", "args": ["build", "/warnaserror"], "include": ["**/*.cs", "**/*.vb"] }, { "name": "eslint", "group": "pre-commit", "pathMode": "absolute", "cwd": "Client", "command": "npm", "args": ["run", "lint", "${staged}"], "include": ["**/*.ts", "**/*.vue", "**/*.js"] }, { "name": "prettier", "group": "pre-commit", "pathMode": "absolute", "cwd": "Client", "command": "npx", "args": ["prettier", "--write", "${staged}"], "include": [ "**/*.ts", "**/*.vue", "**/*.js", "**/*.json", "**/*.yml", "**/*.css", "**/*.scss" ] }, { "name": "Welcome", "output": "always", "command": "bash", "args": ["-c", "echo Nice work! 🥂"], "windows": { "command": "cmd", "args": ["/c", "echo Nice work! 🥂"] } }, { "name": "Run JB Clean Up Code", "command": "cmd", "pathMode": "relative", "args": [ "/c", "dotnet", "jb", "cleanupcode", "proj.sln", "--profile=Team: Full Cleanup", "--include=${args}" ], "group": "pre-commit" } ] } ``` -------------------------------- ### Configure Task Runner for C# Script Execution Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/csharp-script.md Integrate C# script execution into your task runner configuration by defining the command and arguments. This example shows how to run a commit linting script. ```json { "command": "dotnet", "args": ["husky", "exec", ".husky/csx/hello.csx"] } ``` -------------------------------- ### Add a Pre-commit Hook Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/getting-started.md Add a new git hook, such as 'pre-commit', to your project. This example adds a hook that echoes a message. Remember to stage the hook file after adding it. ```shell dotnet husky add pre-commit -c "echo 'Husky.Net is awesome!'" git add .husky/pre-commit ``` -------------------------------- ### Example Commit Message Linter Script Source: https://context7.com/alirezanet/husky.net/llms.txt A C# script example for validating commit messages against conventional commit standards. It returns 0 for valid messages and 1 for invalid ones. ```csharp /// /// Conventional commits linter /// https://www.conventionalcommits.org/en/v1.0.0/ /// using System.Text.RegularExpressions; private var pattern = @"^(?=.{1,90}$)(?:build|feat|ci|chore|docs|fix|perf|refactor|revert|style|test)(?:\[.+\])!?(?::).{4,}(?:#\d+)*(? ``` -------------------------------- ### Executing C# Scripts with Husky Source: https://context7.com/alirezanet/husky.net/llms.txt Run C# script files (.csx) directly from hooks for complex logic. Arguments can be passed to the script using the --args flag. ```bash # Execute a C# script directly dotnet husky exec .husky/csx/hello.csx ``` ```bash # Execute with arguments dotnet husky exec .husky/csx/commit-lint.csx --args ".git/COMMIT_EDITMSG" ``` ```bash # Execute without caching (useful during development) dotnet husky exec .husky/csx/my-script.csx --no-cache ``` -------------------------------- ### Advanced Task Configuration Options Source: https://context7.com/alirezanet/husky.net/llms.txt Configure tasks with advanced options for fine-grained control. This includes specifying branch patterns, path modes, working directories, output behavior, and platform-specific commands. ```json { "tasks": [ { "name": "advanced-task", "command": "dotnet", "args": ["format", "--include", "${staged}"], "group": "pre-commit", "branch": "^(main|develop)$", "pathMode": "relative", "cwd": "src/MyProject", "output": "always", "include": ["**/*.cs"], "exclude": ["**/Generated/**", "**/Migrations/**"], "filteringRule": "staged", "windows": { "command": "cmd", "args": ["/c", "dotnet", "format", "--include", "${staged}"] } } ] } ``` -------------------------------- ### Add Git Hooks with Husky.Net Source: https://context7.com/alirezanet/husky.net/llms.txt Add Git hooks to your project using the `dotnet husky add` command. You can specify the hook name and the command to execute. Remember to add the hook file to Git. ```bash # Add a pre-commit hook that echoes a message dotnet husky add pre-commit -c "echo 'Husky.Net is awesome!'" # Add the hook file to Git git add .husky/pre-commit # Add a pre-push hook that runs tests dotnet husky add pre-push -c "dotnet test" # Add a commit-msg hook that runs the task runner dotnet husky add commit-msg -c "dotnet husky run --name commit-message-linter --args \$1" # Set (replace) a hook with a new command dotnet husky set pre-commit -c "dotnet husky run --group pre-commit" ``` -------------------------------- ### Add Pre-commit Hook with Task Runner Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/task-runner.md Use this command to add a pre-commit hook that executes defined tasks using `dotnet husky run`. Ensure tasks are tested before adding to hooks. ```shell dotnet husky add pre-commit -c "dotnet husky run --group pre-commit" ``` -------------------------------- ### Execute C# Script in Git Hook Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/csharp-script.md Use the `dotnet husky exec` command to run a C# script from your Git hook. Specify the path to your .csx file. ```shell dotnet husky exec # e.g # dotnet husky exec .husky/csx/hello.csx ``` -------------------------------- ### Manual Husky Attachment Target Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/automate.md Manually attach Husky to your project by adding this MSBuild target to your .csproj or .vbproj file. Ensure the 'HuskyRoot' property correctly points to the repository root. ```xml ../../ ``` -------------------------------- ### Run Husky.Net Tasks Source: https://context7.com/alirezanet/husky.net/llms.txt Execute tasks defined in `task-runner.json` manually or filter by name and group using the `dotnet husky run` command. Options include verbose output, quiet mode, and passing custom arguments. ```bash # Run all tasks dotnet husky run # Run tasks in a specific group (e.g., pre-commit hooks) dotnet husky run --group pre-commit # Run a specific task by name dotnet husky run --name dotnet-format # Run with verbose output dotnet husky run -v --group pre-commit # Run quietly (suppress Husky output) dotnet husky run --quiet --group pre-commit # Pass custom arguments to tasks (available as ${args}) dotnet husky run --name commit-message-linter --args ".git/COMMIT_EDITMSG" # Disable unicode characters for terminals without emoji support dotnet husky run --no-unicode --group pre-commit ``` -------------------------------- ### Husky.Net Task Runner Configuration Source: https://context7.com/alirezanet/husky.net/llms.txt Configure the task runner in `.husky/task-runner.json` to define tasks that run on specific hooks. You can specify commands, arguments, include/exclude patterns, and more. ```json { "$schema": "https://alirezanet.github.io/Husky.Net/schema.json", "tasks": [ { "name": "dotnet-format", "group": "pre-commit", "command": "dotnet", "args": ["format", "--include", "${staged}"], "include": ["**/*.cs", "**/*.vb"] }, { "name": "run-tests", "group": "pre-push", "command": "dotnet", "args": ["test", "--no-build"], "include": ["**/*.cs"] }, { "name": "csharpier", "group": "pre-commit", "command": "dotnet", "args": ["csharpier", "${staged}"], "include": ["**/*.cs"] }, { "name": "eslint", "group": "pre-commit", "pathMode": "absolute", "cwd": "ClientApp", "command": "npm", "args": ["run", "lint", "${staged}"], "include": ["**/*.ts", "**/*.tsx", "**/*.js"] }, { "name": "build-check", "group": "pre-push", "command": "dotnet", "args": ["build", "/warnaserror"], "include": ["**/*.cs"] } ] } ``` -------------------------------- ### Task Runner Configuration for Commit Linting Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/csharp-script.md JSON configuration for the task runner, specifying the execution of the commit-msg hook which includes the C# commit linter. ```json { "tasks": { "commit-msg": { "script": ".husky/commit-msg" } } } ``` -------------------------------- ### MsBuild Target for Attaching Husky Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/submodules.md This MsBuild target is used to attach Husky to a project, with options to ignore submodules. Adjust 'HuskyRoot' to the relative path from your project to the repo root. ```xml ../../ ``` -------------------------------- ### Defining Custom Variables with Commands Source: https://context7.com/alirezanet/husky.net/llms.txt Define custom variables that execute commands and return output for use in task arguments. The 'staged' property can be used to directly reference staged files. ```json { "variables": [ { "name": "root-dir-files", "command": "bash", "args": ["-c", "ls -la"] }, { "name": "staged-diff-files", "command": "git", "args": ["diff", "--cached", "--name-only", "--no-ext-diff", "--diff-filter=ACMRTUXB"], "staged": true } ], "tasks": [ { "name": "echo-root-files", "command": "echo", "args": ["${root-dir-files}"] }, { "name": "format-custom-staged", "group": "pre-commit", "command": "dotnet", "args": ["csharpier", "${staged-diff-files}"], "include": ["**/*.cs"] } ] } ``` -------------------------------- ### Uninstalling Husky Hooks Source: https://context7.com/alirezanet/husky.net/llms.txt Remove Husky hooks from your Git configuration by running the uninstall command. This will revert the core.hooksPath setting. ```bash # Uninstall Husky hooks (removes core.hooksPath config) dotnet husky uninstall ``` ```bash # Verify hooks are removed git config --get core.hooksPath # Should return empty ``` -------------------------------- ### Task Arguments with Staged Files Variable Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/task-configuration.md Use the `${staged}` variable to pass currently staged files as arguments to a command. Ensure the variable is correctly formatted within the JSON array. ```json "args": [ "${staged}" ] ``` -------------------------------- ### Conditional Husky Attachment for Multi-Targeted Projects Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/automate.md To prevent Husky from running multiple times in projects with multiple target frameworks, add the 'IsCrossTargetingBuild' condition to the MSBuild target. ```xml ... ``` -------------------------------- ### Using Built-in Variables in Task Arguments Source: https://context7.com/alirezanet/husky.net/llms.txt Access Git file states and custom arguments within task definitions using built-in variables like ${staged}, ${last-commit}, and ${git-files}. ```json { "tasks": [ { "name": "format-staged", "command": "dotnet", "args": ["format", "--include", "${staged}"], "include": ["**/*.cs"] }, { "name": "check-last-commit", "command": "dotnet", "args": ["format", "--verify-no-changes", "--include", "${last-commit}"], "include": ["**/*.cs"] }, { "name": "lint-all-tracked", "command": "dotnet", "args": ["format", "--include", "${git-files}"], "include": ["**/*.cs"] }, { "name": "commit-linter", "command": "dotnet", "args": ["husky", "exec", ".husky/csx/commit-lint.csx", "--args", "${args}"] } ] } ``` -------------------------------- ### Commit Message Linter Hook Configuration Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/csharp-script.md The commit-msg Git hook script that invokes the C# commit message linter. ```shell #!/bin/sh -e . "$PWD/.husky/common.sh" run_hook "commit-msg" "$@" ``` -------------------------------- ### Disabling Husky in CI/CD Pipelines Source: https://context7.com/alirezanet/husky.net/llms.txt Disable Husky hooks in CI/CD environments by setting the HUSKY environment variable to 0. This prevents hooks from running during automated builds and restores. ```bash # Disable Husky via environment variable export HUSKY=0 dotnet restore # Husky install will be skipped ``` ```yaml # In GitHub Actions workflow - name: Build env: HUSKY: 0 run: dotnet build ``` ```yaml # In Azure DevOps pipeline - script: dotnet build env: HUSKY: 0 ``` -------------------------------- ### Commit Message Linter Script Source: https://github.com/alirezanet/husky.net/blob/master/docs/guide/csharp-script.md A C# script used for linting commit messages. This script is executed by the commit-msg hook. ```csharp using System; using System.IO; var commitMsg = File.ReadAllText(".git/COMMIT_EDITMSG"); if (commitMsg.Contains("fix")) { Console.WriteLine("Commit message contains fix"); } else { Console.WriteLine("Commit message does not contain fix"); Environment.Exit(1); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.