小匕首-dotnet cli使用tool指令

美男子玩编程

共 4535字,需浏览 10分钟

 ·

2022-04-15 19:59

点击上方蓝色字体,关注我们


一、指令清单

指令详情

 >dotnet tool -h
 Description:
  安装或使用扩展 .NET 体验的工具。
 
 Usage:
  dotnet [options] tool [command]
 
 Options:
   -?, -h, --help 显示命令行帮助。
 
 Commands:
  install   安装全局或本地工具。本地工具将被添加到清单并还原。
  uninstall 卸载全局工具或本地工具。
  update     更新全局工具。
  list                   列出全局或本地安装的工具。
  run     运行本地工具。
  search <搜索词>           在 nuget.org 中搜索 dotnet 工具
  restore                 还原本地工具清单中定义的工具。

二、工具列表

查看安装列表

 >dotnet tool list -h
 Description:
  列出全局或本地安装的工具。
 
 Usage:
  dotnet [options] tool list
 
 Options:
   -g, --global       列出为当前用户安装的工具。
   --local             列出在本地工具清单中安装的工具。
   --tool-path 包含要列出的工具的目录。
   -?, -h, --help     显示命令行帮助。

net 6上述指令结构应该是dotnet tool list [options],其他指令同理,执行如下:

 >dotnet tool list -g
 包 ID                     版本         命令
 -----------------------------------------------
 dotnet-ef                 5.0.4     dotnet-ef
 redth.net.maui.check      0.8.6     maui-check

三、查询工具

查询输入使用 search 指令

 >dotnet tool search -h
 Description:
  在 nuget.org 中搜索 dotnet 工具
 
 Usage:
  dotnet [options] tool search <搜索词>
 
 Arguments:
  <搜索词> 包 ID 或包说明中的搜索词。至少需要一个字符。
 
 Options:
   --detail       显示查询的详细结果。
   --skip   用于分页的要跳过的结果数。
   --take   用于分页的要返回的结果数。
   --prerelease   正在确定是否包括预发行包。
   -?, -h, --help 显示命令行帮助。

查询工具 redth.net.maui.check,不显示详细信息返回,最新版本。

 >dotnet tool search redth.net.maui
 包 ID                     最新版本       作者         下载         已验证
 --------------------------------------------------------------
 redth.net.maui.check      0.8.6     Redth      60500

显示详细版本,使用 detail,内容如下:

 >dotnet tool search redth.net.maui --detail
 ----------------
 redth.net.maui.check
 最新版本: 0.8.6
 作者: Redth
 标记:
 下载: 60500
 已验证: False
 说明: A dotnet tool for helping set up your .NET MAUI environment
 版本:
         #省略部分旧内容
         0.7.3 下载: 5410
         0.7.5 下载: 86
         0.7.6 下载: 174
         0.7.7 下载: 3173
         0.8.0 下载: 90
         0.8.1 下载: 131
         0.8.2 下载: 304
         0.8.4 下载: 4808
         0.8.5 下载: 815
         0.8.6 下载: 3202

显示部分查询结果

 >dotnet tool search redth.net.maui --skip 0 --take 30
 包 ID                     最新版本       作者         下载         已验证
 --------------------------------------------------------------
 redth.net.maui.check      0.8.6     Redth      60500

四、安装工具

安装使用指令install,分为当前目录安装与全局安装。

4.1、当前目录安装

默认安装需要用户创建工具清单,在当前需要该工具的根目录执行 dotnet new tool-manifest,用户创建清单文件。

未创建清单常见错误信息提示如下:

 找不到清单文件。
 要获取已搜索的位置列表,请在工具名称之前指定 "-d" 选项。
 如果你打算安装全局工具,请在命令中添加 `--global`
 如果你想要创建一个清单,请使用 `dotnet new tool-manifest`,通常位于存储库的根目录中。

创建当前目录的工具配置文件,指令如下:

>dotnet new tool-manifest --force
已成功创建模板“Dotnet 本地工具清单文件”。
>tree .
卷 文档卷 的文件夹 PATH 列表
卷序列号为 9813-5795
E:\STUDY\DEMO\DOS
└─.config

.config 文件夹中,生成一个 dotnet-tools.json,内容初始如下:

{
"version": 1,
"isRoot": true,
"tools": {}
}

为当前目录安装并配置软件清单,默认安装为最新版本,可以使用--version xxx指定版本,操作如下:

>dotnet tool install redth.net.maui.check
你可以使用以下命令从此目录调用工具: "dotnet tool run maui-check" 或 "dotnet maui-check"。
工具“redth.net.maui.check”(版本“0.8.6”)已成功安装。条目将添加到清单文件 xxxx\.config\dotnet-tools.json 中。
# 指定版本
>dotnet tool install redth.net.maui.check --version 0.8.4
你可以使用以下命令从此目录调用工具: "dotnet tool run maui-check" 或 "dotnet maui-check"。
工具“redth.net.maui.check”(版本“0.8.4”)已成功安装。条目将添加到清单文件 E:\Study\Demo\Dos\.config\dotnet-tools.json 中。

对应的配置清单中,内容如下:

{
"version": 1,
"isRoot": true,
"tools": {
"redth.net.maui.check": {
"version": "0.8.6",
"commands": [
"maui-check"
]
}
}
}

查看列表清单,输出如下:

>dotnet tool list
包 ID 版本 命令 清单
------------------------------------------------------------------------------------------------
redth.net.maui.check 0.8.6 maui-check xxxx\.config\dotnet-tools.json

4.2、全局安装

在不创建,特定目录下的清单时,采用全局安装,指令 install 尾部添加 -g,具体操作如下:

>dotnet tool install -g  redth.net.maui.check --version  0.8.4
可使用以下命令调用工具: maui-check
已成功安装工具“redth.net.maui.check”(版本“0.8.4”)。

查看工具列表如下:

>dotnet tool list -g
包 ID 版本 命令
-----------------------------------------------
redth.net.maui.check 0.8.4 maui-check

五、更新工具

更新指令为 update ,同样分为当前工具清单与全局更新,更新时默认为更新到最新版本,可以通过 --version 需要更新的版本。

当前目录更新,指令如下:

>dotnet tool update redth.net.maui.check --version  0.8.5
工具“redth.net.maui.check”已成功从版本“0.8.4”更新到版本“0.8.5”(清单文件 xxx\.config\dotnet-tools.json)。

全局更新,指令如下:

>dotnet tool update -g redth.net.maui.check --version  0.8.5
工具“redth.net.maui.check”已成功从版本“0.8.4”更新到版本“0.8.5”。

六、卸载工具

卸载使用 uninstall 指令,默认为当前目录工具清单工具卸载,添加 -g 表示卸载全局工具。

>dotnet tool uninstall  redth.net.maui.check -g
已成功卸载工具“redth.net.maui.check”(版本“0.8.5”).


往期推荐



点击阅读原文,更精彩~
浏览 68
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报