Skip to content

dotnet --version fails if global.json specifies a newer SDK version #2334

@martincostello

Description

@martincostello

I've been using dotnet --version for some time in build environments to determine whether or not the version of the .NET Core SDK I need for my build is already installed. If not, I download it and install it locally.

With .NET Core SDK 2.1.200 and later, the behaviour has changed so that if global.json in the current directory specifies a newer version that the version of dotnet that is invoked, rather than just returning its own version, it now errors with the following message:

A compatible SDK version for global.json version: [{version in global.json}] from [{working directory}\global.json] was not found
Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
  http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

Given that dotnet --version is such a simple command, it should not matter what is in global.json, particularly for scenarios such as this where it is likely that a newer version is wanted and the command is just being used for version detection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions