Switch between dotnet core SDK versions

You can do this with a global.json file in the root of your project:

  • Verify the list of SDKs on your machine:
dotnet --list-sdks

You’ll see a list like this.

2.1.100 [C:\Program Files\dotnet\sdk]
2.1.101 [C:\Program Files\dotnet\sdk]
2.1.103 [C:\Program Files\dotnet\sdk]
2.1.104 [C:\Program Files\dotnet\sdk]
[...lines omitted...]
2.1.601 [C:\Program Files\dotnet\sdk]
2.2.101 [C:\Program Files\dotnet\sdk]
3.0.100-preview3-010431 [C:\Program Files\dotnet\sdk]
  • Create a folder to be the root of your project, where you are going to run dotnet new.
  • In that folder, run this command: dotnet new globaljson

The result will look something like this:

{
  "sdk": {
    "version": "3.0.100-preview3-010431"
  }
}
  • In version, replace the 3.0.100-preview3-010431 with the version you prefer from the --list-sdks list. For example:
{
  "sdk": {
    "version": "2.2.101"
  }
}
  • Run dotnet --version to verify. You should see:
2.2.101
  • Run the appropriate dotnet new commands to create your project.

Leave a Comment