Skip to content

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

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

Open
lahsrah opened this issue Mar 5, 2025 · 2 comments
Open

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

lahsrah opened this issue Mar 5, 2025 · 2 comments
Assignees
Labels
Area-CLI untriaged Request triage from a team member

Comments

@lahsrah
Copy link

lahsrah commented Mar 5, 2025

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'.
@ghost ghost added Area-CLI untriaged Request triage from a team member labels Mar 5, 2025
@KalleOlaviNiemitalo
Copy link
Contributor

dotnet-format.runtimeconfig.json in .NET SDK 8.0.309 is:

{
  "runtimeOptions": {
    "tfm": "net8.0",
    "rollForward": "LatestMajor",
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "8.0.13"
    },
    "configProperties": {
      "System.GC.Server": true,
      "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
      "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
    }
  }
}

I suppose the "LatestMajor" setting comes from dotnet/format#694. I don't know what that PR was intended to fix and whether "LatestMajor" is still necessary after #38857.

@KalleOlaviNiemitalo
Copy link
Contributor

KalleOlaviNiemitalo commented Mar 5, 2025

However, if the .NET Runtime version 9.0.2 causes dotnet-format to fail with the "source text did not have an identifiable encoding" error that is shown in #46780, then that seems a breaking change that may hurt other applications as well.

In contrast, if the error is more connected to the version of dotnet-format itself, then I don't expect that removing the "LatestMajor" setting will fix it.

In my testing with .NET SDK versions 8.0.309, 9.0.103, and 9.0.200 installed and global.json pointing to 8.0.309, the dotnet-format binary came from .NET SDK 8.0.309 even though it was executed on .NET Runtime 9.0.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants