dotnet / dotnet/sdk

`dotnet new global.json --sdk-version` incorrectly accepts invalid SDK versions like `9.0.x`, emit error instead

Open
#50,460 1 comment 0 reactions 0 assignees View on GitHub
Area-CLI
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Is your feature request related to a problem? Please describe.
Since https://github.com/dotnet/runtime/pull/118418 adds a warning in `dotnet --info` for invalid version strings in .NET 10, let's stop one vector where you can add an invalid version string since not everyone will run `dotnet --info`.

The invalid version formats:
`9` i.e ^\d+$
`9.0` i.e ^\d+\.\d+$
`9.0.0` i.e ^\d+\.\d+\.\d+$
`9.0.x` i.e ^\d+\.\d+\.[xX]$

and only allow the format `9.0.100` i.e ^\d+\.\d+\.(?:[1-9]\d{2})$

(Note: \d allows non 0-9 digits i.e digits from other "languages" so would be better to be explicit and only allow the range 0-9)

### Describe the solution you'd like
Ideally error on invalid version strings, maybe provide a way to force it.

### Additional context
Ref: #49816
Ref: https://github.com/dotnet/runtime/pull/118418 adding a warning for `dotnet --info`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.