nuget-manager
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNuGet Manager
NuGet包管理器
Overview
概述
This skill ensures consistent and safe management of NuGet packages across .NET projects. It prioritizes using the CLI to maintain project integrity and enforces a strict verification and restoration workflow for version updates.
dotnet此技能确保在.NET项目中一致且安全地管理NuGet包。它优先使用 CLI来维护项目完整性,并为版本更新强制执行严格的验证和还原工作流。
dotnetPrerequisites
前提条件
- .NET SDK installed (typically .NET 8.0 SDK or later, or a version compatible with the target solution).
- CLI available on your
dotnet.PATH - (JSON processor) OR PowerShell (for version verification using
jq).dotnet package search
- 已安装.NET SDK(通常为.NET 8.0 SDK或更高版本,或与目标解决方案兼容的版本)。
- CLI已添加到您的
dotnet中。PATH - (JSON处理器)或PowerShell(用于通过
jq进行版本验证)。dotnet package search
Core Rules
核心规则
- NEVER directly edit ,
.csproj, or.propsfiles to add or remove packages. Always useDirectory.Packages.propsanddotnet add packagecommands.dotnet remove package - DIRECT EDITING is ONLY permitted for changing versions of existing packages.
- VERSION UPDATES must follow the mandatory workflow:
- Verify the target version exists on NuGet.
- Determine if versions are managed per-project () or centrally (
.csproj).Directory.Packages.props - Update the version string in the appropriate file.
- Immediately run to verify compatibility.
dotnet restore
- 绝不直接编辑、
.csproj或.props文件来添加或移除包。始终使用Directory.Packages.props和dotnet add package命令。dotnet remove package - 直接编辑仅允许用于更改现有包的版本。
- 版本更新必须遵循强制工作流:
- 验证目标版本在NuGet上是否存在。
- 确定版本是按项目()管理还是集中管理(
.csproj)。Directory.Packages.props - 在相应文件中更新版本字符串。
- 立即运行以验证兼容性。
dotnet restore
Workflows
工作流
Adding a Package
添加包
Use .
Example:
dotnet add [<PROJECT>] package <PACKAGE_NAME> [--version <VERSION>]dotnet add src/MyProject/MyProject.csproj package Newtonsoft.Json使用。
示例:
dotnet add [<PROJECT>] package <PACKAGE_NAME> [--version <VERSION>]dotnet add src/MyProject/MyProject.csproj package Newtonsoft.JsonRemoving a Package
移除包
Use .
Example:
dotnet remove [<PROJECT>] package <PACKAGE_NAME>dotnet remove src/MyProject/MyProject.csproj package Newtonsoft.Json使用。
示例:
dotnet remove [<PROJECT>] package <PACKAGE_NAME>dotnet remove src/MyProject/MyProject.csproj package Newtonsoft.JsonUpdating Package Versions
更新包版本
When updating a version, follow these steps:
-
Verify Version Existence: Check if the version exists using thecommand with exact match and JSON formatting. Using
dotnet package search:jqUsing PowerShell:dotnet package search <PACKAGE_NAME> --exact-match --format json | jq -e '.searchResult[].packages[] | select(.version == "<VERSION>")'(dotnet package search <PACKAGE_NAME> --exact-match --format json | ConvertFrom-Json).searchResult.packages | Where-Object { $_.version -eq "<VERSION>" } -
Determine Version Management:
- Search for in the solution root. If present, versions should be managed there via
Directory.Packages.props.<PackageVersion Include="Package.Name" Version="1.2.3" /> - If absent, check individual files for
.csproj.<PackageReference Include="Package.Name" Version="1.2.3" />
- Search for
-
Apply Changes: Modify the identified file with the new version string.
-
Verify Stability: Runon the project or solution. If errors occur, revert the change and investigate.
dotnet restore
更新版本时,请遵循以下步骤:
-
验证版本存在性: 使用带精确匹配和JSON格式的命令检查版本是否存在。 使用
dotnet package search:jq使用PowerShell:dotnet package search <PACKAGE_NAME> --exact-match --format json | jq -e '.searchResult[].packages[] | select(.version == "<VERSION>")'(dotnet package search <PACKAGE_NAME> --exact-match --format json | ConvertFrom-Json).searchResult.packages | Where-Object { $_.version -eq "<VERSION>" } -
确定版本管理方式:
- 在解决方案根目录中搜索。如果存在,版本应通过
Directory.Packages.props在其中管理。<PackageVersion Include="Package.Name" Version="1.2.3" /> - 如果不存在,检查各个文件中的
.csproj。<PackageReference Include="Package.Name" Version="1.2.3" />
- 在解决方案根目录中搜索
-
应用更改: 修改已识别的文件,更新版本字符串。
-
验证稳定性: 在项目或解决方案上运行。如果出现错误,还原更改并进行调查。
dotnet restore
Examples
示例
User: "Add Serilog to the WebApi project"
用户:"将Serilog添加到WebApi项目"
Action: Execute .
dotnet add src/WebApi/WebApi.csproj package Serilog操作:执行。
dotnet add src/WebApi/WebApi.csproj package SerilogUser: "Update Newtonsoft.Json to 13.0.3 in the whole solution"
用户:"将整个解决方案中的Newtonsoft.Json更新到13.0.3"
Action:
- Verify 13.0.3 exists: (and parse output to confirm "13.0.3" is present).
dotnet package search Newtonsoft.Json --exact-match --format json - Find where it's defined (e.g., ).
Directory.Packages.props - Edit the file to update the version.
- Run .
dotnet restore
操作:
- 验证13.0.3是否存在:(并解析输出以确认"13.0.3"存在)。
dotnet package search Newtonsoft.Json --exact-match --format json - 查找其定义位置(例如)。
Directory.Packages.props - 编辑文件以更新版本。
- 运行。
dotnet restore