convert-to-cpm
它能做什么
这项技能把各个项目中的 NuGet 包版本移到一个集中文件中,这种设置称为集中包管理(Central Package Management)。适合多个项目的包版本已经出现偏差的团队。
适用场景
- ✓当解决方案中的多个项目使用同一 NuGet 包的不同版本时。
- ✓当你希望通过 Directory.Packages.props 文件采用集中包管理时。
- ✓当你需要在整个仓库中统一包版本时。
技能链接
https://github.com/dotnet/skills/blob/main/plugins/dotnet-nuget/skills/convert-to-cpm/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我的解决方案有十个项目,它们使用的 Newtonsoft.Json 版本各不相同。你能把它们集中到一个文件中吗?”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会检查项目是否使用 PackageReference,规划版本变更,创建集中文件,然后构建以确认项目仍然正常工作。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Convert to Central Package Management
Centralize package versions in Directory.Packages.props while preserving project behavior and producing reviewable before/after evidence.
Choose a mode first
Do this before running builds or changing files.
- Guard mode -- If any in-scope project uses
packages.config, stop. Explain that CPM requiresPackageReferenceand recommend migrating first. Do not create or modify files. - Package-maintenance mode -- A request to update, align, bump, or sync packages authorizes those package edits, not CPM conversion. Audit the named scope, resolve the requested versions, update existing project/shared version declarations, and restore/build every affected CLI target from the directory that establishes its applicable
global.json. Ask only when the version or alignment policy is ambiguous. Do not create or modifyDirectory.Packages.props, remove versions for CPM, or capture conversion artifacts. Complete the package work, then recommend CPM as the durable follow-up. - Conversion mode -- Use only when the user explicitly asks to adopt, enable, or convert to CPM. Follow the workflow below.
If the scope is unclear, ask once before proceeding.
Default execution plan
- Guard: use a minimal scoped detection pass, then answer and stop.
- Package maintenance: use a compact audit, edit only the requested package versions in their existing locations, validate affected targets, then recommend CPM. Do not read conversion references or enter the conversion workflow.
- Conversion: batch the preflight, baseline, audit/mutation, final validation, and report work to avoid redundant turns. Revisit a stage only when new CPM-specific evidence requires a targeted follow-up.
This plan is an efficiency default, not a hard cap. Never omit an in-scope project, imported .props/.targets file, detected complexity, required validation, or deliverable to save a turn. Batch complete work where practical.
Inputs
| Input | Required | Rule |
|---|---|---|
| Scope | Yes | Project, solution, or directory containing the projects to inspect or convert |
| Conflict strategy | For package maintenance or conversion with conflicts | If the user already supplied a strategy such as "use the highest version," apply it without asking again and record its impact. Otherwise stop after the audit and ask before editing. |
Read references only when needed
Never preload all references.
| Condition | Read |
|---|---|
| Entering conversion baseline or producing the package diff | baseline-comparison.md |
A conflict, conditional reference, shared import, security concern, or VersionOverride is detected |
audit-complexities.md |
Placement is unclear or conditional PackageVersion/VersionOverride is required |
directory-packages-props.md |
| A package version uses an MSBuild property | msbuild-property-handling.md |
| Restore or build fails after conversion | validation-and-errors.md |
| Writing the final report | report-template.md |
Conversion workflow
1. Scope and preflight
- Resolve the project/solution scope. For a solution, list its projects. For a directory, search only beneath that directory and create an explicit target set that covers the full scope: use each applicable
.sln/.slnx, then add each project not covered by a solution. Verify that every in-scope project is covered and avoid duplicate work for projects that occur in more than one target. Ask only when overlapping targets or repository boundaries make the intended coverage ambiguous; never ask the user to select one target when that would omit in-scope projects. - Determine CPM management scopes separately from CLI targets. Group projects that will share one central version policy and place one
Directory.Packages.propsat each group's first common ancestor, while respecting existing nearest-file boundaries. Multiple CLI targets can share one CPM file; independent project groups can require separate files. - Check for
packages.config; if found, switch to Guard mode and stop. - Check the scope and ancestors for
Directory.Packages.props. If CPM is already fully enabled, report that and stop. If a partial file exists, preserve it and as
常见问题
如果项目仍在使用 packages.config 怎么办?
这项技能会停止,并建议先迁移到 PackageReference,此时它不会修改任何文件。
它只更新版本吗?
如果你要求更新或对齐包,它会完成这项工作,并建议把集中管理作为下一步。
它支持 .slnx 文件吗?
支持。它同时支持 .sln 和 .slnx 解决方案文件以及单个项目。
详情
作者的原始描述
Convert .NET projects and solutions (.sln, .slnx) to NuGet Central Package Management (CPM) using Directory.Packages.props. USE FOR: converting to CPM, centralizing or aligning NuGet package versions across multiple projects, inlining MSBuild version properties from Directory.Build.props into Directory.Packages.props, resolving version conflicts or mismatches across a solution or repository, updating or bumping or syncing package versions across projects. Also activate when packages are out of sync, drifting, or inconsistent -- even without the user mentioning CPM. Provides baseline build capt
repo: dotnet/skills
热度
- GitHub 星标
- 5.8k
- 排名
- #14610
- 许可证
- MIT
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
create-custom-agent
5.8k帮你的智能体创建 VS Code 自定义智能体文件,为每个智能体设置专属工具、指令以及向其他智能体的交接。
create-skill
5.8k帮你的智能体创建新的智能体技能,包括有效的名称、清晰的触发描述,以及符合标准的 SKILL.md 文件。
csharp-scripts
5.8k帮你的智能体通过 .NET 命令行工具以单个文件运行小型 C# 程序,无需创建完整项目。
dotnet-pinvoke
5.8k帮你的智能体在 .NET 中正确调用原生 C 或 C++ 库,涵盖函数签名、字符串处理、内存和安全句柄。