Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cn-ml opened this issue Jun 8, 2024 · 1 comment
Open

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

cn-ml opened this issue Jun 8, 2024 · 1 comment

Comments

@cn-ml
Copy link

cn-ml commented Jun 8, 2024

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
@snus-kin
Copy link

snus-kin commented Jul 12, 2024

From the readme:

Going forward, the .NET format team is using the dotnet/sdk repository for further development and respond to issues formerly in that repository.

The sdk repo has no option for a repo-based pre-commit hook but, .pre-commit-config.yaml file that looks like:

repos:
-   repo: local
    hooks:
    -   id: dotnet-format
        name: dotnet-format
        language: system
        entry: dotnet format --include
        types_or: ["c#", "vb"]

may suffice, if you're not needing dotnet format to be installed seperately from your system's dotnet tools.

Otherwise you will have to install the named SDK preview version.

More info here: https://github.com/dotnet/format/blob/archive/docs/integrations.md#pre-commitcom-hook-to-reformat

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants