Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
345 views
in Technique[技术] by (71.8m points)

c# - 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 Filesdotnetsdk 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 Filesdotnetsdk]
2.1.101 [C:Program Filesdotnetsdk]
2.1.103 [C:Program Filesdotnetsdk]
2.1.104 [C:Program Filesdotnetsdk]
[...lines omitted...]
2.1.601 [C:Program Filesdotnetsdk]
2.2.101 [C:Program Filesdotnetsdk]
3.0.100-preview3-010431 [C:Program Filesdotnetsdk]
  • 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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...