Skip to content

Show error when using invalid global.json version string like 9.0.x #49816

@Frulfump

Description

@Frulfump

Is your feature request related to a problem? Please describe

Ref: dependabot/dependabot-core#12396 (comment)
and dependabot/dependabot-core#12638 (comment)

According to this https://learn.microsoft.com/en-us/dotnet/core/tools/global-json a version string of 9.0.x doesn't seem to be supported

This field:

Doesn't have wildcard support; that is, you must specify the full version number.
Doesn't support version ranges.

(Noticed when preparing this repro that dotnet new global.json happily accepts the invalid version string, should I report that in the dotnet/templating repo? UPDATE: Created here #50460)

And as can be seen below the dotnet --info command shows that the invalid version string is silently ignored. It even prints

global.json file:
  Not found

which is surprising.

dotnet command outputs

➜ dotnet new global.json --sdk-version 9.0.x
The template "global.json file" was created successfully.

➜ dotnet new console
The template "Console App" was created successfully.
...

➜ dotnet build
...
Build succeeded in 2,6s

➜ dotnet --info
.NET SDK:
 Version:           10.0.100-preview.6.25358.103
 Commit:            75972a5ba7
 Workload version:  10.0.100-manifests.6616851e
 MSBuild version:   17.15.0-preview-25358-103+75972a5ba

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\10.0.100-preview.6.25358.103\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.

Host:
  Version:      10.0.0-preview.6.25358.103
  Architecture: x64
  Commit:       75972a5ba7

.NET SDKs installed:
  8.0.412 [C:\Program Files\dotnet\sdk]
  9.0.302 [C:\Program Files\dotnet\sdk]
  10.0.100-preview.6.25358.103 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 8.0.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 9.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 10.0.0-preview.6.25358.103 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 8.0.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 9.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 10.0.0-preview.6.25358.103 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 8.0.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 9.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 10.0.0-preview.6.25358.103 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

The Dependabot team is currently choosing to adapt to the invalid version by guessing what the user wants and use the latest .NET 9 SDK but this leads to a different SDK being used in their runs compared to what the user potentially will see locally and in their own CI. I'm arguing their approach can lead to "interesting" issues and they don't want to add a warning or error unless the SDK already does so dependabot/dependabot-core#12638 (comment)

cc @JamieMagee @brettfo @randhircs

Describe the solution you'd like

Ideally an error is provided, put it behind a TFM check (if possible, might not be as in the case with dotnet new console but just error out anyways people can fix their code, don't be afraid of that breaking people they need to move to a new SDK anyways) so it's not just tied to the SDK used and require net10.0 and above, .NET 8 goes out of support November 10:th 2026 and .NET 9 May 12:th 2026 https://dotnet.microsoft.com/en-us/platform/support/policy which is soon enough. Could consider having it as a warning for 9.0.4xx which hasn't been released yet and unlikely to meet the servicing bar for 8.0.1xx or 8.0.4xx.

Additional context

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions