1.查看当前版本
dotnet --version
C:\Users\18749>dotnet --version
7.0.306
2.查看所有版本信息
dotnet --info
C:\Users\18749>dotnet --info
.NET SDK:Version: 7.0.306Commit: f500069cb7运行时环境:OS Name: WindowsOS Version: 10.0.22621OS Platform: WindowsRID: win10-x64Base Path: C:\Program Files\dotnet\sdk\7.0.306\Host:Version: 7.0.9Architecture: x64Commit: 8e9a17b221.NET SDKs installed:6.0.412 [C:\Program Files\dotnet\sdk]7.0.306 [C:\Program Files\dotnet\sdk].NET runtimes installed:Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]Microsoft.AspNetCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]Microsoft.AspNetCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]Microsoft.NETCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]Microsoft.NETCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]Microsoft.WindowsDesktop.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]Microsoft.WindowsDesktop.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]Other architectures found:x86 [C:\Program Files (x86)\dotnet]registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]Environment variables:Not setglobal.json file:Not foundLearn more:https://aka.ms/dotnet/infoDownload .NET:https://aka.ms/dotnet/download
我们看到安装了两个版本,因此可以切换
.NET SDKs installed:
6.0.412 [C:\Program Files\dotnet\sdk]
7.0.306 [C:\Program Files\dotnet\sdk]
3.版本切换
dotnet new globaljson --sdk-version 版本号 --force
C:\Users\18749>dotnet new globaljson --sdk-version 6.0.412 --force
已成功创建模板“global.json file”。C:\Users\18749>dotnet --version
6.0.412
现在就切换好了!