Skip to content

Allow pinned SDK to be used for dotnet format command #47282

Open
@lahsrah

Description

@lahsrah

Is your feature request related to a problem? Please describe.

dotnet format command is broken in 9.0.200 that was installed by Visual Studio and no update is available as of now. #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.

Describe the solution you'd like

dotnet format command to respect pinned sdk in global.json file.

Additional context

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

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions