用途:该技能用于管理 .NET 本地工具(local tools),即按仓库而非全局安装和锁定版本的 .NET CLI 工具。适合在团队中统一工具链、让 CI/CD 与本地开发使用相同工具版本、管理项目专用 CLI 工具(如 docfx、incrementalist、dotnet-ef 等),并避免不同项目间的全局工具版本冲突。
主要能力:本地工具定义在 .config/dotnet-tools.json 中,通过 dotnet tool restore 还原。与全局工具相比,本地工具按仓库隔离、版本写入版本控制、CI/CD 只需一条还原命令。清单字段包括 version(模式版本,固定为 1)、isRoot(标记根清单,阻止向父目录搜索)、tools 字典,其中每个工具含 version(精确版本)、commands(提供的 CLI 命令)、rollForward(是否允许更新版本,通常为 false 以保证可复现)。
使用方式:用 dotnet new tool-manifest 初始化清单;用 dotnet tool install <工具名>(可加 --version 或 --add-source)本地安装;用 dotnet tool restore 还原全部工具;用 dotnet tool update、dotnet tool list(含 --outdated)、dotnet tool uninstall 管理。清单中示例工具包括 docfx、dotnet-ef、dotnet-reportgenerator-globaltool、incrementalist.cmd、csharpier、jb。CI 中先执行 dotnet tool restore 再调用工具,并提供了 GitHub Actions 与 Azure Pipelines 的示例片段。
限制与注意:部分工具(如 JB dotnet-inspect)需许可证;应在仓库根目录运行工具,否则会报找不到工具;若出现版本冲突,可检查全局工具(dotnet tool list -g)或父目录下的多个清单;可用 dotnet nuget locals all --clear 清理缓存后重新还原。建议始终设置 isRoot: true、用 rollForward: false 锁定精确版本、在 CI 中先还原、在 README 记录工具要求,并可借助 Dependabot 更新。具体工具版本号请以资料所示为准。