Skip to content

allow targetting a specific sdk version when running dotnet format command #2233

Closed
@lahsrah

Description

@lahsrah

dotnet format command is broken in 9.0.200 that was installed by Visual Studio and no update is available as of now. dotnet/sdk#46780

I want to be able to run dotnet format command that is part of 8.x.x but it doesn't seem possible. I tried using a global.json file to pin .net 8 to my project but format command still uses 9.0.200 on my machine.

global.json to pin dotnet 8 to my project

{
  "sdk": {
    "version": "8.0.406",
    "rollForward": "latestFeature"
  }
}

SDKs installed on my machine:

> dotnet --list-sdks
8.0.406 [C:\Program Files\dotnet\sdk]
9.0.200 [C:\Program Files\dotnet\sdk]

SDK dotnet command uses after pinning via global.json

> dotnet --version
8.0.406 [C:\Program Files\dotnet\sdk]

dotnet build respects pinned version

> dotnet build -v d
Build started 5/03/2025 5:35:58 PM.
     0>Process = "C:\Program Files\dotnet\dotnet.exe"
     MSBuild executable path = "C:\Program Files\dotnet\sdk\8.0.406\MSBuild.dll"
     ...

dotnet format does not respect pinned version

> dotnet format -v d
  The dotnet runtime version is '9.0.2'.
  Formatting code files in workspace 'C:\Data\Code\demo-project\demo-project.csproj'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions