Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch between dotnet core SDK versions

I recently installed VS 2017 RC and then automatically my dotnet version pointed to 1.0.0-preview4-004233. Due to that whenever I create a new project using command dotnet new -t Console I cannot see project.json though I see .csproj file.

When I check dotnet versions available on my machine at - C:\Program Files\dotnet\sdk I see multiple versions available.

Is there any way to switch dotnet core back to an earlier version - 1.0.0-preview2-003133 from 1.0.0-preview4-004233 without uninstalling.

like image 621
Avi Kenjale Avatar asked Feb 06 '17 21:02

Avi Kenjale


People also ask

How do I change the dotnet SDK version?

In order to change default dotnet SDK version, place a global. json file in the current folder or any parent folder with the contents below. You can create the global. json file manually, or use the dotnet cli command dotnet new globaljson .

Can you have multiple versions of .NET Core?

You may have multiple versions of . NET Core installed on same box and some applications may need some specific version of . NET Core. This is why installers doesn't remove previous versions.

How do I change the .NET Core version in Visual Studio code?

Open your project's source folder and in the address bar, type "cmd" and press Enter. It will open the Command Prompt with the project path. Execute the following command. It will display your project's current SDK version, i.e., 2.1.

Can I remove older versions of .NET Core SDK?

NET Runtime updates are compatible with the latest major version of the . NET SDKs. This means that you can remove safely the older versions.


2 Answers

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.
like image 118
Set Avatar answered Sep 29 '22 12:09

Set


Dotnet usually uses the latest SDK version, unless it finds a global.json file that tells it to do otherwise. The explanation by microsoft

dotnet looks for the file in the working directory (not necessarily the project or solution directory), and if it can't find one it starts searching upwards from there. documentation

An easy way to create a global.json file would be to run dotnet new globaljson --sdk-version 1.0.0-preview2-003133 in the directory of your project. create a global.json from the cli

like image 27
Alenros Avatar answered Sep 29 '22 12:09

Alenros