alirezanet / Husky.Net

Git hooks made easy with Husky.Net internal task runner! 🐶 It brings the dev-dependency concept to the .NET world!
https://alirezanet.github.io/Husky.Net/
MIT License
684 stars 31 forks source link

git commit 提示 dotnet-format 不存在 #46

Closed Jesn closed 2 years ago

Jesn commented 2 years ago

Version

0.4.4

Details

[Husky] Matches:
  microservices/IdentityService.Host/IdentityServiceHostModule.cs
  microservices/IdentityService.Host/Program.cs
  microservices/IdentityService.Host/Startup.cs
  microservices/IdentityService.Host/Controllers/HomeController.cs
  microservices/IdentityService.Host/Tenants/TenantCreatedDistributedEventHandler.cs
[Husky] ? Executing task 'dotnet-format' ...
无法执行,因为找不到指定的命令或文件。
可能的原因包括:
  *内置的 dotnet 命令拼写错误。
  *你打算执行 .NET 程序,但 dotnet-dotnet-format 不存在。
  *你打算运行全局工具,但在路径上找不到具有此名称且前缀为 dotnet 的可执行文件。

Steps to reproduce

alirezanet commented 2 years ago

Hi @Jesn, You should provide more information to let me reproduce if there is a problem. according to this result, you probably have a configuration problem in your task-runner.json.

Jesn commented 2 years ago

@alirezanet this is my task-runner.json

{
  "variables": [
    {
      "name": "root-dir",
      "command": "cmd",
      "args": [ "/c", "dir", "/b" ]
    }
  ],
  "tasks": [
    {
      "name": "dotnet-format",
      "group": "pre-commit",
      "command": "dotnet",
      "args": [ "dotnet-format", "--include", "${staged}" ],
      "include": [ "**/*.cs" ]
    },
    {
      "name": "commit-message-linter",
      "group": "pre-commit",
      "command": "dotnet",
      "args": [
        "husky",
        "exec",
        ".husky/csx/commit-lint.csx",
        "--args",
        "${args}"
      ]
    }
  ]
}
alirezanet commented 2 years ago

Probably you didn't install dotnet format. Make sure it is installed locally, (check .config\dotnet-tools.json)

 dotnet tool list --local
husky              0.4.4           husky              path-to-project\.config\dotnet-tools.json
dotnet-format      5.1.250801      dotnet-format      path-to-project\.config\dotnet-tools.json

eg: cat .\.config\dotnet-tools.json

{
  "version": 1,
  "isRoot": true,
  "tools": {
    "husky": {
      "version": "0.4.4",
      "commands": [
        "husky"
      ]
    },
    "dotnet-format": {
      "version": "5.1.250801",
      "commands": [
        "dotnet-format"
      ]
    }
  }
}