Sdk: Is there a way to choose the SDK version that dotnet CLI should use?

Created on 3 Feb 2017  ยท  2Comments  ยท  Source: dotnet/sdk

  • After installing 1.0.0-rc3-004530 (via sudo apt-get install 1.0.0-rc3-004530), dot-net CLI defaults to 1.0.0-rc3-004530. That means dotnet new creates projects with .csproj and MSBuild.
  • I am working on two projects, one on the 1.0.0-preview2-1-003177 (with project.json) and the other (I want to experiment) using 1.0.0-rc3-004530.
  • I want to be able to instruct dotnet CLI to use a specific SDK version when doing dotnet new and other commands.

Is there a way to choose the SDK version that dotnet CLI should use?

Thanks!

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc3-004530)

Product Information:
 Version:            1.0.0-rc3-004530
 Commit SHA-1 hash:  10b642bc12

Runtime Environment:
 OS Name:     ubuntu
 OS Version:  16.04
 OS Platform: Linux
 RID:         ubuntu.16.04-x64
 Base Path:   /usr/share/dotnet/sdk/1.0.0-rc3-004530

How my dotnet folder looks like:

.
โ”œโ”€โ”€ host
โ”‚ย ย  โ””โ”€โ”€ fxr
โ”‚ย ย      โ”œโ”€โ”€ 1.0.1
โ”‚ย ย      โ””โ”€โ”€ 1.1.0
โ”œโ”€โ”€ sdk
โ”‚ย ย  โ”œโ”€โ”€ 1.0.0-preview2-1-003177
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ runtimes
โ”‚ย ย  โ””โ”€โ”€ 1.0.0-rc3-004530
โ”‚ย ย      โ”œโ”€โ”€ 15.0
โ”‚ย ย      โ”œโ”€โ”€ Extensions
โ”‚ย ย      โ”œโ”€โ”€ Roslyn
โ”‚ย ย      โ”œโ”€โ”€ runtimes
โ”‚ย ย      โ”œโ”€โ”€ Sdks
โ”‚ย ย      โ”œโ”€โ”€ Templates
โ”‚ย ย      โ””โ”€โ”€ TestHost
โ””โ”€โ”€ shared
    โ””โ”€โ”€ Microsoft.NETCore.App
        โ”œโ”€โ”€ 1.0.3
        โ””โ”€โ”€ 1.1.0

```

Most helpful comment

You can use a global.json like the one below. Put it in the root of your repo and if you run a dotnet command from a folder containing that file (or an child folder), that version will be respected.

{
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

All 2 comments

You can use a global.json like the one below. Put it in the root of your repo and if you run a dotnet command from a folder containing that file (or an child folder), that version will be respected.

{
  "sdk": {
    "version": "1.0.0-preview2-1-003177"
  }
}

@livarcocc Thanks. I finally added the global.json as you suggested.

However, I suppose my scenario was little different. My projects are still on sdk 1.0.0-preview2-1-003177. I am working on porting them in a phased manner to 1.0.0-rc3-004530, which is not yet released here.

While I continue to experiment with rc3, I would to continue create and work with preview2 style (project.json) projects. I would like have both SDKs on my machine and choose which SDK to use.

For instance, during experimentation when I wanted to convert project.json projects to .csproj, dotnet migrate was not working (not recognized) from within my projects folder (I had global.json already before raising this issue here). I took a while for me to figure you have to be outside the project folder where there is no global.json and so would be using the latest SDK version (rc3 in our case).

The other thing that was inconvenient to me is I cannot simply dotnet new to create a project.json project. I will have to create the global.json first.

Just sharing my experience ...

Was this page helpful?
0 / 5 - 0 ratings