用于安装/升级.NET 核心的命令行

是否有安装或升级.NETCore 的命令行命令?

我查过了。NET 核心是安装在我的计算机上使用 dotnet --version只是注意到,我仍然有预览版本安装在我的计算机上。我想知道是否可以发出一些命令将其升级到最新版本。

95581 次浏览

There is no dotnet command to update .Net Core. Instead, you should use the same approach you used to install it in the first place, which depends on your OS.

Just a heads up so you (or other people) don't struggle for hours as I did.

.NET Core 1.1.0 ships with SDK 1.0.0 Preview 2 (when this is written), but you need SDK 1.0.0 Preview 3.

Download and install .NET Core 1.1.0 as @svick suggested, then download and install SDK Preview 3 from: https://github.com/dotnet/core/blob/master/release-notes/preview3-download.md

Not promoted officially but it looks like there are approved packages on Chocolatey for .NET Core SDK.

https://chocolatey.org/packages/dotnetcore-sdk

Example:

> choco install dotnetcore-sdk

Or:

> choco upgrade dotnetcore-sdk

Update (December 2020): For .NET 5 the chocolatey package has changed since it's not technically branded as .NET Core any longer.

https://chocolatey.org/packages/dotnet-sdk/

Example:

> choco install dotnet-sdk

Or:

> choco upgrade dotnet-sdk

For those who find this on search, there are dotnet-install scripts you can use. For example:

# Windows PowerShell
Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile "$env:temp/dotnet-install.ps1"; powershell -executionpolicy bypass "$env:temp/dotnet-install.ps1"


# PowerShell Core
Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile "$env:temp/dotnet-install.ps1"; pwsh "$env:temp/dotnet-install.ps1"


# Shell
wget https://dot.net/v1/dotnet-install.sh && chmod +x ./dotnet-install.sh && sudo ./dotnet-install.sh

* Note the default install location for these is different than the official installers; as said in another answer the easiest path to update is to use the same method you first installed with.

Edit: apt packages for Ubuntu 22.04+ now includes dotnet6 for the SDK. Other dotnet packages, such as just the runtime (dotnet-runtime-6.0, aspnet-runtime-6.0) can be installed as well.

sudo apt update
sudo apt install dotnet6

If you have WinGet, then you can use it to install (or update) .NET:

winget install Microsoft.DotNet.SDK.Preview    # currently .NET 7
winget install Microsoft.DotNet.SDK.6
winget install Microsoft.DotNet.SDK.5
winget install Microsoft.DotNet.SDK.3_1

Run from an admin prompt