dotnet tool installdotnet tool install

本文适用于: ✔️ .NET Core 2.1 SDK 及更高版本This article applies to: ✔️ .NET Core 2.1 SDK and later versions

“属性”Name

dotnet tool install - 在计算机上安装指定的 .NET Core 工具dotnet tool install - Installs the specified .NET Core tool on your machine.

摘要Synopsis

dotnet tool install <PACKAGE_NAME> -g|--global
    [--add-source <SOURCE>] [--configfile <FILE>]
    [--framework <FRAMEWORK>] [-v|--verbosity <LEVEL>]
    [--version <VERSION_NUMBER>]

dotnet tool install <PACKAGE_NAME> --tool-path <PATH>
    [--add-source <SOURCE>] [--configfile <FILE>]
    [--framework <FRAMEWORK>] [-v|--verbosity <LEVEL>]
    [--version <VERSION_NUMBER>]

dotnet tool install <PACKAGE_NAME>
    [--add-source <SOURCE>] [--configfile <FILE>]
    [--framework <FRAMEWORK>] [-v|--verbosity <LEVEL>]
    [--version <VERSION_NUMBER>]

dotnet tool install -h|--help

描述Description

dotnet tool install 命令为用户提供一种在计算机上安装 .NET Core 工具的方法。The dotnet tool install command provides a way for you to install .NET Core tools on your machine. 若要使用命令,请指定以下安装选项之一:To use the command, you specify one of the following installation options:

  • 若要在默认位置中安装全局工具,请使用 --global 选项。To install a global tool in the default location, use the --global option.
  • 若要在自定义位置中安装全局工具,请使用 --tool-path 选项。To install a global tool in a custom location, use the --tool-path option.
  • 若要安装本地工具,请省略 --global--tool-path 选项。To install a local tool, omit the --global and --tool-path options.

本地工具从 .NET Core SDK 3.0 开始可用。Local tools are available starting with .NET Core SDK 3.0.

指定 -g--global 选项时,全局工具默认安装在以下目录中:Global tools are installed in the following directories by default when you specify the -g or --global option:

(OS)OS 路径Path
Linux/macOSLinux/macOS $HOME/.dotnet/tools
WindowsWindows %USERPROFILE%\.dotnet\tools

本地工具将添加到当前目录下 .config 目录中的 dotnet-tools.json 文件中。Local tools are added to a dotnet-tools.json file in a .config directory under the current directory. 如果清单文件尚不存在,请通过运行以下命令来创建它:If a manifest file doesn't exist yet, create it by running the following command:

dotnet new tool-manifest

有关详细信息,请参阅安装本地工具For more information, see Install a local tool.

自变量Arguments

  • PACKAGE_NAME

    包含要安装的 .NET Core 工具的 NuGet 包的名称/ID。Name/ID of the NuGet package that contains the .NET Core tool to install.

选项Options

  • add-source <SOURCE>

    添加安装过程中要使用的其他 NuGet 包源。Adds an additional NuGet package source to use during installation.

  • configfile <FILE>

    要使用的 NuGet 配置 (nuget.config) 文件。The NuGet configuration (nuget.config) file to use.

  • framework <FRAMEWORK>

    指定要安装工具的目标框架Specifies the target framework to install the tool for. 默认情况下,.NET Core SDK 尝试选择最合适的目标框架。By default, the .NET Core SDK tries to choose the most appropriate target framework.

  • -g|--global

    指定安装是用户范围的。Specifies that the installation is user wide. 不能与 --tool-path 选项一起使用。Can't be combined with the --tool-path option. 省略 --global--tool-path 指定本地工具安装。Omitting both --global and --tool-path specifies a local tool installation.

  • -h|--help

    打印出有关命令的简短帮助。Prints out a short help for the command.

  • tool-path <PATH>

    指定全局工具的安装位置。Specifies the location where to install the Global Tool. 路径可以是绝对的,也可以是相对的。PATH can be absolute or relative. 如果路径不存在,命令会尝试创建它。If PATH doesn't exist, the command tries to create it. 省略 --global--tool-path 指定本地工具安装。Omitting both --global and --tool-path specifies a local tool installation.

  • -v|--verbosity <LEVEL>

    设置命令的详细级别。Sets the verbosity level of the command. 允许使用的值为 q[uiet]m[inimal]n[ormal]d[etailed]diag[nostic]Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic].

  • --version <VERSION_NUMBER>

    要安装的工具版本。The version of the tool to install. 默认情况下,安装最新的稳定包版本。By default, the latest stable package version is installed. 使用此选项安装工具的预览版或较旧版本。Use this option to install preview or older versions of the tool.

示例Examples

  • dotnet tool install -g dotnetsay

    在默认位置中安装 dotnetsay 全局工具。Installs dotnetsay as a global tool in the default location.

  • dotnet tool install dotnetsay --tool-path c:\global-tools

    在特定 Windows 目录中安装 dotnetsay 全局工具。Installs dotnetsay as a global tool in a specific Windows directory.

  • dotnet tool install dotnetsay --tool-path ~/bin

    在特定 Linux/macOS 目录中安装 dotnetsay 全局工具。Installs dotnetsay as a global tool in a specific Linux/macOS directory.

  • dotnet tool install -g dotnetsay --version 2.0.0

    安装 2.0.0 版的 dotnetsay 全局工具。Installs version 2.0.0 of dotnetsay as a global tool.

  • dotnet tool install dotnetsay

    在当前目录中安装 dotnetsay 本地工具。Installs dotnetsay as a local tool for the current directory.

请参阅See also