dotnet / format

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

pre-commit not compatible with dotnet5 #1499

Open joshschmitter opened 2 years ago

joshschmitter commented 2 years ago

Hello, dotnet-format seems to work great in my environment except with pre-commit: the pre-commit installation seems to require net6. Installing the net6 sdk solves the issue, but my whole team is still on net5. Seems it should be backward compatible.

To reproduce:

  - repo: https://github.com/dotnet/format
    rev: v5.1.225507
    hooks:
      - id: dotnet-format
        args: [--include]

Expected result:

The pre-commit hook should run.

Actual result:

An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/dotnet', 'pack', '--configuration', 'Release', '--output', 'pre-commit-build')
return code: 145
expected return code: 0
stdout:
            5.0.403 [/usr/share/dotnet/sdk]

stderr:
    Could not execute because the application was not found or a compatible .NET SDK is not installed.
    Possible reasons for this include:
      * You intended to execute a .NET program:
          The application 'pack' does not exist.
      * You intended to execute a .NET SDK command:
          A compatible installed .NET SDK for global.json version [6.0.100-preview.1.21103.13] from [/home/myuser/.cache/pre-commit/repozyfxg1_6/global.json] was not found.
          Install the [6.0.100-preview.1.21103.13] .NET SDK or update [/home/myuser/.cache/pre-commit/repozyfxg1_6/global.json] with an installed .NET SDK:

Check the log at /home/myuser/.cache/pre-commit/pre-commit.log

Additional Info:

I tried updating the dotnet versions in the global.json file. The pre-commit hook seems to get a little farther, but finally throws this error:

An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/dotnet', 'tool', 'install', '--tool-path', '/home/a1587448/.cache/pre-commit/repoxtgbj1_6/dotnetenv-default/bin', '--add-source', 'pre-commit-build', 'dotnet-format')
return code: 1
expected return code: 0
stdout:
    error NU1202: Package dotnet-format 7.0.255502 is not compatible with net5.0 (.NETCoreApp,Version=v5.0) / any. Package dotnet-format 7.0.255502 supports: net6.0 (.NETCoreApp,Version=v6.0) / any

stderr:
    The tool package could not be restored.
    Tool 'dotnet-format' failed to install. This failure may have been caused by:

    * You are attempting to install a preview release and did not use the --version option to specify the version.
    * A package by this name was found, but it was not a .NET tool.
    * The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
    * You mistyped the name of the tool.

    For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool

Check the log at /home/a1587448/.cache/pre-commit/pre-commit.log

That makes me wonder if the pre-commit environment is installing too-recent of a dotnet-format package.

Thanks in advance!

joshschmitter commented 2 years ago

Here's my pre-commit.log as well: pre-commit.log