跳到正文
Skillpedia
部署与云(DevOps)5.8k · #14610

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/dotnet/skills/blob/main/plugins/dotnet-nuget/skills/convert-to-cpm/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

  1. Guard mode -- If any in-scope project uses packages.config, stop. Explain that CPM requires PackageReference and recommend migrating first. Do not create or modify files.
  2. 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 modify Directory.Packages.props, remove versions for CPM, or capture conversion artifacts. Complete the package work, then recommend CPM as the durable follow-up.
  3. 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.props at 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能