在 dotnet 核心 SDK 版本之间切换 [英] Switch between dotnet core SDK versions
问题描述
我最近安装了 VS 2017 RC,然后我的 dotnet 版本自动指向 1.0.0-preview4-004233
.因此,每当我使用命令 dotnet new -t Console
创建新项目时,我都看不到 project.json
尽管我看到了 .csproj
文件.
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.
当我在我的机器上检查可用的 dotnet 版本时 - C:Program Filesdotnetsdk
我看到多个可用版本.
When I check dotnet versions available on my machine at - C:Program Filesdotnetsdk
I see multiple versions available.
有什么方法可以将 dotnet core 切换回早期版本 - 1.0.0-preview2-003133
来自 1.0.0-preview4-004233
而无需卸载.
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.
推荐答案
您可以使用项目根目录中的 global.json
文件执行此操作:
You can do this with a global.json
file in the root of your project:
- 验证您机器上的 SDK 列表:
dotnet --list-sdks
您会看到这样的列表.
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]
- 创建一个文件夹作为项目的根目录,您将在其中运行
dotnet new
. - 在该文件夹中,运行以下命令:
dotnet new globaljson
结果看起来像这样:
{
"sdk": {
"version": "3.0.100-preview3-010431"
}
}
- 在
version
中,将3.0.100-preview3-010431
替换为--list-sdks
列表中您喜欢的版本.例如: - In
version
, replace the3.0.100-preview3-010431
with the version you prefer from the--list-sdks
list. For example:
{
"sdk": {
"version": "2.2.101"
}
}
- 运行
dotnet --version
进行验证.您应该看到: - Run
dotnet --version
to verify. You should see:
2.2.101
- 运行适当的
dotnet new
命令来创建您的项目. - Run the appropriate
dotnet new
commands to create your project.
这篇关于在 dotnet 核心 SDK 版本之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!