dotnet-install 指令碼參考dotnet-install scripts reference

名稱Name

dotnet-install.ps1 | dotnet-install.sh- 用於安裝 .NET 核心 SDK 和共用運行時的腳本。dotnet-install.ps1 | dotnet-install.sh - Script used to install the .NET Core SDK and the shared runtime.

概要Synopsis

Windows:Windows:

dotnet-install.ps1 [-Channel] [-Version] [-JSonFile] [-InstallDir] [-Architecture]
    [-Runtime] [-DryRun] [-NoPath] [-Verbose] [-AzureFeed] [-UncachedFeed] [-NoCdn] [-FeedCredential]
    [-ProxyAddress] [-ProxyUseDefaultCredentials] [-SkipNonVersionedFiles] [-Help]

Linux/macOs:Linux/macOs:

dotnet-install.sh [--channel] [--version] [--jsonfile] [--install-dir] [--architecture]
    [--runtime] [--dry-run] [--no-path] [--verbose] [--azure-feed] [--uncached-feed] [--no-cdn] [--feed-credential]
    [--runtime-id] [--skip-non-versioned-files] [--help]

描述Description

這些dotnet-install腳本用於執行 .NET 核心 SDK 的非管理員安裝,其中包括 .NET Core CLI 和共用運行時。The dotnet-install scripts are used to perform a non-admin installation of the .NET Core SDK, which includes the .NET Core CLI and the shared runtime.

我們建議您使用腳本的穩定版本:We recommend that you use the stable version of the scripts:

這些指令碼對於自動化案例和非系統管理員安裝非常有幫助。The main usefulness of these scripts is in automation scenarios and non-admin installations. 有兩個指令碼:一個是在 Windows 上運作的 PowerShell 指令碼,另一個是在 Linux/macOS 上運作的 Bash 指令碼。There are two scripts: one is a PowerShell script that works on Windows, and the other is a bash script that works on Linux/macOS. 這兩個指令碼有相同的行為。Both scripts have the same behavior. Bash 指令碼也能讀取 PowerShell 參數,因此您可以搭配 PowerShell 參數使用 Linux/macOS 系統上的指令碼。The bash script also reads PowerShell switches, so you can use PowerShell switches with the script on Linux/macOS systems.

安裝指令碼會從 CLI 組建放置區下載 ZIP/tarball 檔案,並且繼續將它安裝在預設位置或 -InstallDir|--install-dir 所指定的位置。The installation scripts download the ZIP/tarball file from the CLI build drops and proceed to install it in either the default location or in a location specified by -InstallDir|--install-dir. 根據預設,安裝指令碼會下載並安裝 SDK。By default, the installation scripts download the SDK and install it. 如果您想要只取得共用執行階段,請指定 -Runtime|--runtime 引數。If you wish to only obtain the shared runtime, specify the -Runtime|--runtime argument.

根據預設,指令碼會將安裝位置新增到目前工作階段的 $PATH。By default, the script adds the install location to the $PATH for the current session. 指定 -NoPath|--no-path 引數可以覆寫此預設行為。Override this default behavior by specifying the -NoPath|--no-path argument.

執行指令碼之前,請安裝所有必要的相依性 (英文)Before running the script, install the required dependencies.

您可以使用 -Version|--version 引數安裝特定版本。You can install a specific version using the -Version|--version argument. 版本必須指定為三部分版本(例如。 2.1.0The version must be specified as a three-part version (for example, 2.1.0). 如果未提供,就會使用 latest 版本。If not provided, it uses the latest version.

選項。Options

  • -Channel|--channel <CHANNEL>

    指定安裝的來源通道。Specifies the source channel for the installation. 可能的值包括:The possible values are:

    • Current - 最新版本。Current - Most current release.
    • LTS - 長期支援通道 (最新的支援版本)。LTS - Long-Term Support channel (most current supported release).
    • 代表特定版本的 X.Y 格式兩段式版本 (例如 2.13.0)。Two-part version in X.Y format representing a specific release (for example, 2.1 or 3.0).
    • 分支名稱:例如,release/3.1.1xxmaster(用於夜間發佈)。Branch name: for example, release/3.1.1xx or master (for nightly releases). 使用此選項可以從預覽頻道安裝版本。Use this option to install a version from a preview channel. 使用安裝程式和二進位檔案中列出的通道的名稱。Use the name of the channel as listed in Installers and Binaries.

    預設值是 LTSThe default value is LTS. 如需有關 .NET 支援通道的詳細資訊,請參閱 .NET Core 支援政策 (英文) 頁面。For more information on .NET support channels, see the .NET Support Policy page.

  • -Version|--version <VERSION>

    代表特定的組建版本。Represents a specific build version. 可能的值包括:The possible values are:

    • latest - 通道上的最新組建 (與 -Channel 選項搭配使用)。latest - Latest build on the channel (used with the -Channel option).
    • coherent - 通道上的最新一致性組建;使用最新的穩定套件組合 (與分支名稱 -Channel 選項搭配使用)。coherent - Latest coherent build on the channel; uses the latest stable package combination (used with Branch name -Channel options).
    • 代表特定組建版本的 X.Y.Z 格式三段式版本;取代 -Channel 選項。Three-part version in X.Y.Z format representing a specific build version; supersedes the -Channel option. 例如:2.0.0-preview2-006120For example: 2.0.0-preview2-006120.

    如果未指定,-Version 會預設為 latestIf not specified, -Version defaults to latest.

  • -JSonFile|--jsonfile <JSONFILE>

    指定用於確定 SDK 版本的global.json檔的路徑。Specifies a path to a global.json file that will be used to determine the SDK version. 全域.json檔必須具有 的值sdk:versionThe global.json file must have a value for sdk:version.

  • -InstallDir|--install-dir <DIRECTORY>

    指定安裝路徑。Specifies the installation path. 如果目錄不存在,則會建立它。The directory is created if it doesn't exist. 預設值是 %LocalAppData%\Microsoft\dotnetThe default value is %LocalAppData%\Microsoft\dotnet. 二進位檔會直接放在此目錄中。Binaries are placed directly in this directory.

  • -Architecture|--architecture <ARCHITECTURE>

    要安裝的 .NET Core 二進位檔的架構。Architecture of the .NET Core binaries to install. 可能的值為 <auto>amd64x64x86arm64armPossible values are <auto>, amd64, x64, x86, arm64, and arm. 預設值為 <auto>,代表目前正在執行的 OS 架構。The default value is <auto>, which represents the currently running OS architecture.

  • -SharedRuntime|--shared-runtime

    注意

    此參數已被淘汰,在未來的指令碼版本中可能會將其移除。This parameter is obsolete and may be removed in a future version of the script. 建議的替代方案是 -Runtime|--runtime 選項。The recommended alternative is the -Runtime|--runtime option.

    只安裝共用執行階段位元,而不是整個 SDK。Installs just the shared runtime bits, not the entire SDK. 此選項等效于指定-Runtime|--runtime dotnetThis option is equivalent to specifying -Runtime|--runtime dotnet.

  • -Runtime|--runtime <RUNTIME>

    只安裝共用執行階段,而不是整個 SDK。Installs just the shared runtime, not the entire SDK. 可能的值包括:The possible values are:

    • dotnet - Microsoft.NETCore.App 共用執行階段。dotnet - the Microsoft.NETCore.App shared runtime.
    • aspnetcore - Microsoft.AspNetCore.App 共用執行階段。aspnetcore - the Microsoft.AspNetCore.App shared runtime.
    • windowsdesktop - Microsoft.WindowsDesktop.App 共用執行階段。windowsdesktop - the Microsoft.WindowsDesktop.App shared runtime.
  • -DryRun|--dry-run

    如果設定,指令碼將不會執行安裝。If set, the script won't perform the installation. 取而代之的是,會顯示以一致方式安裝目前所要求的 .NET Core CLI 版本時,所要使用的命令列。Instead, it displays what command line to use to consistently install the currently requested version of the .NET Core CLI. 例如,如果您指定 latest 版本,就會顯示特定版本的連結,以便在建置指令碼中以決定性方式使用此命令。For example, if you specify version latest, it displays a link with the specific version so that this command can be used deterministically in a build script. 如果您想要自行進行安裝或下載,它也會顯示二進位檔位置。It also displays the binary's location if you prefer to install or download it yourself.

  • -NoPath|--no-path

    如果設定,就不會將安裝資料夾匯出至目前工作階段的路徑。If set, the installation folder isn't exported to the path for the current session. 預設情況下,腳本修改 PATH,使 .NET 核心 CLI 在安裝後立即可用。By default, the script modifies the PATH, which makes the .NET Core CLI available immediately after install.

  • -Verbose|--verbose

    顯示診斷資訊。Displays diagnostics information.

  • -AzureFeed|--azure-feed

    指定給安裝程式的 Azure 摘要 URL。Specifies the URL for the Azure feed to the installer. 建議您不要變更這個值。We recommended that you don't change this value. 預設值是 https://dotnetcli.azureedge.net/dotnetThe default value is https://dotnetcli.azureedge.net/dotnet.

  • -UncachedFeed|--uncached-feed

    允許變更此安裝程式所使用之未快取摘要的 URL。Allows changing the URL for the uncached feed used by this installer. 建議您不要變更這個值。We recommended that you don't change this value.

  • -NoCdn|--no-cdn

    不允許從 Azure 內容傳遞網路 (CDN) 下載,而直接使用未快取的摘要。Disables downloading from the Azure Content Delivery Network (CDN) and uses the uncached feed directly.

  • -FeedCredential|--feed-credential

    用來作為要附加至 Azure 摘要的查詢字串。Used as a query string to append to the Azure feed. 這可允許變更 URL 以使用非公用 Blob 儲存體帳戶。It allows changing the URL to use non-public blob storage accounts.

  • --runtime-id

    指定正在為其安裝工具的運行時識別碼Specifies the runtime identifier for which the tools are being installed. 用於linux-x64可擕式 Linux。Use linux-x64 for portable Linux. (僅適用于 Linux/macOS)(Only valid for Linux/macOS)

  • -ProxyAddress

    如果設定,安裝程式會使用此 Proxy 進行 Web 要求。If set, the installer uses the proxy when making web requests. (只適用於 Windows)(Only valid for Windows)

  • ProxyUseDefaultCredentials

    如果設定,當使用 Proxy 位址時,安裝程式會使用目前使用者的認證。If set, the installer uses the credentials of the current user when using proxy address. (只適用於 Windows)(Only valid for Windows)

  • -SkipNonVersionedFiles|--skip-non-versioned-files

    如果已經有非版本控制的檔案 (例如 dotnet.exe) 存在,便略過其安裝。Skips installing non-versioned files, such as dotnet.exe, if they already exist.

  • -Help|--help

    印出指令碼的說明。Prints out help for the script.

範例Examples

  • 將最新的長期支援 (LTS) 版本安裝至預設位置︰Install the latest long-term supported (LTS) version to the default location:

    Windows:Windows:

    ./dotnet-install.ps1 -Channel LTS
    

    macOS/Linux:macOS/Linux:

    ./dotnet-install.sh --channel LTS
    
  • 將最新版本從 3.1 通道安裝到指定位置:Install the latest version from 3.1 channel to the specified location:

    Windows:Windows:

    ./dotnet-install.ps1 -Channel 3.1 -InstallDir C:\cli
    

    macOS/Linux:macOS/Linux:

    ./dotnet-install.sh --channel 3.1 --install-dir ~/cli
    
  • 安裝共用運行時的 3.0.0 版本:Install the 3.0.0 version of the shared runtime:

    Windows:Windows:

    ./dotnet-install.ps1 -Runtime dotnet -Version 3.0.0
    

    macOS/Linux:macOS/Linux:

    ./dotnet-install.sh --runtime dotnet --version 3.0.0
    
  • 取得指令碼並在公司 Proxy 後方安裝 2.1.2 版本 (僅適用於 Windows):Obtain script and install the 2.1.2 version behind a corporate proxy (Windows only):

    Invoke-WebRequest 'https://dot.net/v1/dotnet-install.ps1' -Proxy $env:HTTP_PROXY -ProxyUseDefaultCredentials -OutFile 'dotnet-install.ps1';
    ./dotnet-install.ps1 -InstallDir '~/.dotnet' -Version '2.1.2' -ProxyAddress $env:HTTP_PROXY -ProxyUseDefaultCredentials;
    
  • 取得指令碼並安裝 .NET Core CLI 單行範例:Obtain script and install .NET Core CLI one-liner examples:

    Windows:Windows:

    # Run a separate PowerShell process because the script calls exit, so it will end the current PowerShell session.
    &powershell -NoProfile -ExecutionPolicy unrestricted -Command "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) <additional install-script args>"
    

    macOS/Linux:macOS/Linux:

    curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin <additional install-script args>
    

另請參閱See also