dotnet / format

Home for the dotnet-format command
MIT License
1.91k stars 172 forks source link

pre-commit hook fails: no compatible SDK was found #2198

Open cn-ml opened 3 weeks ago

cn-ml commented 3 weeks ago

I was trying to run the formatting hook, but it shows me that i have an incompatible dotnet SDK installed. I do have both .NET 8 and .NET 6 installed, both of which should at least be backward compatible (major and patch-only). I already issued this at pre-commit but the maintainer said, that "this is not a framework issue".

pre-commit configuration

# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
default_install_hook_types:
  - pre-commit # usual behaviour
  - commit-msg # required for commitlint
default_stages:
  - pre-commit # prevent hooks to run twice for commit-msg hook
repos:
  - repo: https://github.com/dotnet/format
    rev: v5.1.225507
    hooks:
      - id: dotnet-format # Format C# files

pre-commit version

pre-commit version: 3.7.1
git --version: git version 2.39.1.windows.1
sys.version:
    3.12.3 (tags/v3.12.3:f6650f9, Apr  9 2024, 14:05:25) [MSC v.1938 64 bit (AMD64)]
sys.executable: C:\Users\Michael\AppData\Local\Programs\Python\Python312\python.exe
os.name: nt
sys.platform: win32

pre-commit log

Traceback (most recent call last):
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\error_handler.py", line 73, in error_handler
    yield
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\main.py", line 389, in main
    return hook_impl(
           ^^^^^^^^^^
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\commands\hook_impl.py", line 271, in hook_impl
    return retv | run(config, store, ns)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\commands\run.py", line 442, in run
    install_hook_envs(to_install, store)
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\repository.py", line 238, in install_hook_envs
    _hook_install(hook)
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\repository.py", line 94, in _hook_install
    lang.install_environment(
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\languages\dotnet.py", line 67, in install_environment
    lang_base.setup_cmd(
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\lang_base.py", line 86, in setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "C:\Users\Michael\AppData\Local\Programs\Python\Python312\Lib\site-packages\pre_commit\util.py", line 111, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('C:\\Program Files\\dotnet\\dotnet.EXE', 'pack', '--configuration', 'Release', '--property', 'PackageOutputPath=C:\\Users\\Michael\\.cache\\pre-commit\\reponw4tf5ex\\pre-commit-build')
return code: 2147516561
stdout:
    6.0.423 [C:\Program Files\dotnet\sdk]
    8.0.300 [C:\Program Files\dotnet\sdk]
stderr:
    The command could not be loaded, possibly because:
      * You intended to execute a .NET application:
          The application 'pack' does not exist.
      * You intended to execute a .NET SDK command:
          A compatible .NET SDK was not found.

    Requested SDK version: 6.0.100-preview.1.21103.13
    global.json file: C:\Users\Michael\.cache\pre-commit\reponw4tf5ex\global.json

    Installed SDKs:

    Install the [6.0.100-preview.1.21103.13] .NET SDK or update [C:\Users\Michael\.cache\pre-commit\reponw4tf5ex\global.json] to match an installed SDK.

    Learn about SDK resolution:
    https://aka.ms/dotnet/sdk-not-found