Skip to navigation

NuGet Central Package Management: Plan a Cross-Project Migration

In short: Find where package versions live, which props file wins, and which overrides need review before a CPM migration.

Published 20 min read
On this page

Direct answer

Central Package Management moves version numbers out of project files and into Directory.Packages.props, where a PackageVersion item declares the version and each PackageReference names only the package. The closest props file to a project is evaluated by default, and parent files need an explicit import. Before moving versions, inventory three things: which nested Directory.Packages.props files exist, which entries carry conditions, and which PackageReference items use VersionOverride. The concrete win is one place per version across the repository. The concrete loss is that a migration which ignores the closest-file rule or an override produces a build where the effective version differs from the one the team thinks it set. The practical implication is that the inventory is the migration, and the edit is the small part. Ask Claude Code to list every props file, every conditional version, and every override before proposing the central file.

Why a blind CPM migration costs a week

Centralizing versions changes where a number is edited, not which packages a project uses. The failure mode is subtle: a build succeeds, the restore log looks normal, and the effective version of a package is not the one anyone intended. A nested props file closer to the project wins. A VersionOverride on one project keeps an old number alive after the central entry moved on. A conditional version that was obvious in the project file becomes invisible once it moves to a file nobody opens.

None of these are restore errors. The migration reports success, and the divergence appears later as a duplicate package, a failed audit, or an upgrade that two engineers believe shipped while the resolved graph says otherwise. Reading the existing structure first turns that from a mystery into a checklist.

Evidence and its limits

Official, F031: Microsoft’s Central Package Management documentation describes PackageVersion items in Directory.Packages.props and PackageReference items without a Version attribute, and records that the closest props file is evaluated by default. Projects can import parent files manually, and overrides or disabled CPM can change the effective result.

Official: The NuGet CPM sample repository is the reference example the documentation points to.

Official: PackageReference in project files documents the item form the projects use after the migration.

Official: Customize builds by directory documents how MSBuild evaluates directory-scoped files such as Directory.Packages.props.

Official: MSBuild conditions documents the condition syntax used by conditional PackageVersion entries.

Official, agent loop: Claude Code best practices recommends pairing an edit with a pass-or-fail check. For this migration that check is a restore plus a diff of the resolved versions.

Derived, F032: The staging order and the inventory tables below are an editorial method, not an official migration order.

No claim here depends on a specific SDK version, NuGet release, or benchmark.

What Central Package Management changes

CPM is a version-location change. The set of packages a project references stays the same. What moves is where the version is written and who can see it.

Concern Before CPM After CPM Unchanged
Where the version lives Each .csproj Directory.Packages.props Package identity
Which packages the project uses PackageReference list PackageReference list Restore behavior
Version conflicts across projects Manual agreement One central entry Runtime behavior
Per-project exceptions Edit the project VersionOverride Intent

Read the table as a scope statement. CPM does not change what is installed. It changes how many places a version number can hide.

Read Directory.Packages.props

Start from the file that will hold the central versions. A minimal one declares ManagePackageVersionsCentrally and lists PackageVersion items.

bash
<Project>
<PropertyGroup>
  <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
  <PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
</Project>

The PackageVersion item carries the version. The project’s PackageReference then names the package without a Version attribute. The documentation in F031 describes this split, and the sample repository shows it in a runnable form.

One property deserves early attention: whether CPM is enabled at all in the current tree. A repo where CPM is disabled in one subtree can look migrated while that subtree still resolves from project-level versions.

Map Project PackageReference Items

The migration moves versions out of project files, so the first inventory is every PackageReference that still carries a Version attribute.

bash
Get-ChildItem -Recurse -Filter *.csproj | Select-String -Pattern 'PackageReference'

For each project, record the package, the version currently written, and whether the reference has a condition. The condition matters because a conditional reference can express framework-specific intent that a flat central entry would lose. The MSBuild conditions page documents the syntax.

Project Package Version in project Conditional Destination
src/Core Newtonsoft.Json 13.0.3 No Central entry
src/Core System.Text.Json 8.0.0 No Central entry
tests/Core.Tests xunit 2.6.0 No Central entry
src/Legacy Newtonsoft.Json 12.0.3 No VersionOverride candidate

Two rows in this table are the decisions the migration actually has to make. A project whose version differs from the intended central version needs either an update or an explicit override, and the override is a visible exception rather than a hidden one.

Find nested props files

The closest-file rule in F031 is the trap. A repository can have a root Directory.Packages.props and a nested one under a subtree, and the nested file wins for the projects it covers. A version added to the root file does nothing for those projects.

Props file Covers Wins for Reachable from root edit
/Directory.Packages.props Everything by default Projects with no closer file Yes, default
/src/Legacy/Directory.Packages.props src/Legacy subtree Its own projects No, closer file wins
/Directory.Packages.props imported manually by a project That project Per the import Explicit import

Look through the repository for every Directory.Packages.props and record what each one covers. A migration that edits only the root file and leaves a nested file in place has not migrated the subtree, whatever the restore log says.

The directory-customization page documents how MSBuild evaluates these directory-scoped files, which is the mechanism behind the closest-file rule.

Inventory Overrides and Conditions

Two constructs keep exceptions visible, and both need an inventory before the migration.

VersionOverride on a PackageReference states that one project uses a different version than the central entry. It is the documented exception mechanism, and leaving one in place after a migration is legitimate when the exception is intended. Leaving one in place when it was forgotten is how an old version survives a “completed” migration.

Conditional PackageVersion entries select different versions for different conditions, most often target framework. The MSBuild conditions reference documents the syntax. A conditional entry is intent, not noise, and flattening it into one version changes what the build resolves.

Construct Meaning Migration action
VersionOverride on a reference Project-level version exception Keep deliberately or reconcile
Conditional PackageVersion Version varies by condition Preserve the condition
ManagePackageVersionsCentrally false in a subtree CPM off locally Decide whether the subtree migrates
Parent props imported manually Non-default evaluation Record the import

Ask Claude Code to report every instance of all four before proposing the central file. The inventory is the artifact that makes the migration reviewable, and the Central Package Management reference is the authority on each construct’s meaning.

Stage the Migration

The inventory decides the order. A staged migration keeps each step reviewable.

First stage, the least ambiguous packages. Packages referenced once with an unconditional version that matches the intended central version move first. The pass condition is a restore that resolves the same versions as before.

Second stage, the differing versions. Each project whose version differs from the intended central version is a decision: update to the central version, or keep the difference with a VersionOverride. Record the decision per project.

Third stage, the conditional entries. Move conditional versions into conditional central entries, preserving the condition. The conditions reference is the syntax check.

Fourth stage, the subtree decisions. A nested props file is either reconciled into the root file or left deliberately, and the decision is recorded next to the file.

bash
dotnet restore
git diff --stat

Run restore after each stage. A restore that resolves different versions than the previous stage is a finding, not a success. The diff of the resolved versions is the verification the whole migration rests on.

Review Package Metadata Impact

CPM does not change which packages a project uses, so the published metadata should not change either. Verify that on the migrated projects rather than trusting the rule.

Artifact Before migration After migration
Package identity Same Same
Resolved version Per project file Per central entry, or override
Project file Version attributes Version-free references
Published dependencies Unchanged Unchanged when versions match

An effective-version diff that shows changes the team did not intend is the concrete defect to look for. Restore once before the migration and once after, and compare the resolved version of every package in the inventory.

A worked walkthrough of one migration

Consider a repository with a root Directory.Packages.props declaring Newtonsoft.Json 13.0.3, and a nested /src/Legacy/Directory.Packages.props declaring 12.0.3. The team decides to move every project to central management and bumps the central entry to 13.0.3.

The instinctive edit is changing the root file and declaring the migration done. It is not. The nested file is closer to the Legacy projects, so the closest-file rule in F031 means those projects still resolve 12.0.3. The restore log is green, the central entry says 13.0.3, and the effective version for Legacy is silently wrong.

The correct sequence starts with the inventory, not the edit.

Sweep the repository for every Directory.Packages.props and record what each covers. Every .csproj also needs checking for PackageReference items still carrying a Version attribute. A third pass covers every VersionOverride and every conditional PackageVersion. The three searches produce the inventory that decides the order.

For the Legacy subtree, the decision is explicit: either reconcile those projects to the central version or keep the nested file deliberately and record why. A deliberate nested file is a legitimate outcome. An accidental one is the defect.

bash
dotnet restore
git diff --name-only

Run restore before and after each stage and compare the resolved version of every package in the inventory. A version that moved when you expected it to stay is the finding to investigate before merging. The resolved-version diff is the verification the whole migration rests on, and it is the only thing that catches a silent closest-file miss.

Anti-patterns that look like migrations

Four patterns recur around CPM work, and each one hides a decision a reviewer needs to see.

Pattern What it looks like Why it hurts Do instead
Editing only the root file Central entry updated, nested file untouched Closest file still governs the subtree Inventory every props file first
Reconciling every override Removing VersionOverride to simplify Deletes an intended exception Keep deliberate overrides, record why
Flattening conditions Replacing a conditional version with one Changes what the build resolves per framework Preserve the condition
Declaring completion on green restore Restore succeeds, migration called done Effective versions can differ silently Compare resolved versions before and after

Flattening conditions deserves the most caution. A conditional central entry that selects a different version per target framework is intent, and .NET multi-targeting covers the per-framework matrix that justifies it. Removing the condition to shorten the file changes resolution on at least one target.

None of these is a NuGet defect. They are review hazards, and the props inventory plus the resolved-version diff are what catch them.

A runbook for the next CPM migration

The checklist earlier in this post is the pass condition. The runbook below is the sequence to follow when a migration request arrives.

Search the repository for every Directory.Packages.props and record its coverage. The closest-file rule makes this the first step, because a migration that misses a nested file has not migrated that subtree.

Search every project file for PackageReference items with a Version attribute, plus every VersionOverride and conditional PackageVersion. This is the candidate set, and each entry is a decision rather than a mechanical move.

Decide the order. Unconditional versions that match the intended central version move first. Differing versions and overrides move second, each with a keep-or-reconcile decision. Conditional entries move third with their conditions preserved. Subtree decisions move last.

Run restore after each stage and compare resolved versions against the previous stage. Paste the diff into the change description.

Record the props inventory, the override decisions, and the conditions in the repository next to the central file. The record is what turns the migration into a durable contract rather than a search-and-replace.

The runbook takes minutes and produces the two artifacts a reviewer needs: the inventory and the resolved-version diff. Skipping it produces a migration that reports success while a subtree resolves an unintended version.

Where this habit pays across the batch

The inventory-first habit in this post is the same one the rest of the batch applies to different constructs. .NET multi-targeting asks for a per-framework matrix before a version change, and C# source generators asks for the generator’s input change before reading its output. Maven optional dependencies asks for an import scan before a declaration.

The JVM posts apply the same discipline to version policy. Gradle constraints vs dependencies asks for a resolved-graph diff, Gradle capability conflicts asks for a component inventory, and Gradle variant attributes asks for the consumer request before a notation change.

The C++ posts apply it to configure inputs and dependency boundaries. CMake presets asks for the resolved preset inputs before a configure, CMake find_package vs FetchContent asks for a resolution trace before choosing a path, and Conan CMakeDeps asks for the target contract before a layout change.

That consistency is deliberate. The constructs differ, but the shape is the same: read the evidence the tool already produces, then make the smallest change the evidence supports.

The same shape extends to the ecosystems covered in earlier batches. On the Python side, dependency groups versus extras separates local workflow requirements from published optional features, and stub drift audits a package’s declared types against its documented runtime surface. TypedDict boundaries covers separating truly optional keys from missing data before replacing broad dictionary annotations.

On the Go side, module compatibility covers keeping an exported API change inside an import contract, and graph pruning covers why an indirect dependency entry is graph metadata rather than something to delete. Workspace boundaries covers deciding what belongs in go.work versus what stays a module requirement.

On the Rust side, feature unification covers mapping which optional APIs a workspace build actually exposes, and workspace inheritance covers centralizing metadata without hiding crate-local exceptions. Profile boundaries covers separating diagnostic and optimization settings from options that change observable program behavior.

Centralizing versions has a direct analog in Cargo workspace inheritance, where the same “centralize what repeats, keep identity local” question applies to workspace metadata rather than package versions. Both are centralization questions, and both reward an inventory before a move.

Working alongside the review bottleneck

A migration with a pasted inventory and resolved-version diff is cheap to review. A migration described as “centralized the versions” is a reviewer reproducing the work, and reproduction is the expensive part. The Claude Code code review bottleneck covers what happens when generation outpaces the review that has to accept it.

The same reasoning appears in Claude Code cost per verified change, which treats verified work as a separate unit from generated output. A resolved-version diff is a verified unit. A “trust me, the versions are central now” description is not.

When the review queue is long enough that verification slips, the failure mode is a merge that nobody actually checked. Prevent false success from passing tests covers the case where a green restore is the only evidence, and a closest-file miss is exactly the case where green proves less than it appears to.

The concrete win, loss, and implication

The concrete win is one place per version. An upgrade that touches ten projects becomes an edit to one central entry, and a security review that asks “which version of this package are we on” has one answer instead of a search.

The concrete loss is the invisible file. A central props file is one more place a version decision can live, and the closest-file rule plus overrides mean the effective version can differ from the obvious one. A migration that skips the inventory produces a repo that is harder to reason about than the one it replaced.

The practical implication is that CPM is a visibility change and visibility has to be built deliberately. Teams that keep the override and condition inventory next to the central file resolve fewer “which version actually shipped” questions. Teams that migrate by search-and-replace spend the difference debugging restore logs.

The .NET posts in this batch cover the neighboring questions. .NET multi-targeting covers per-framework package versions, which is where conditional central entries earn their place. C# source generators covers reviewing a generated contract rather than its output.

The JVM posts cover version policy in a different ecosystem. Gradle constraints vs dependencies covers version policy without graph edges, and Maven optional dependencies covers which optional libraries a consumer must declare directly.

For C++ builds, CMake presets covers making configure inputs explicit, CMake find_package vs FetchContent covers choosing a dependency boundary, and Conan CMakeDeps covers keeping consumer target names stable.

Review habits sit upstream of every migration step. Ask what Claude Code verification requires before calling a stage done, and a migration that also reformats project files is the pattern the Claude Code overengineering guide warns about.

Evidence map showing a central Directory.Packages.props declaring PackageVersion items while project PackageReference items name packages without versions, with the closest props file winning.
Editorial evidence map based on F031 and F032. By default MSBuild evaluates the closest Directory.Packages.props; parent files need an explicit import.

Checklist before merging a CPM migration

Run this list against the diff. Each row is a pass condition.

Check Pass condition If it fails
Props file inventory Every Directory.Packages.props listed with coverage Search the repo first
Version inventory Every project-level version recorded Complete the reference scan
Override inventory Every VersionOverride recorded with intent Decide keep or reconcile
Condition inventory Every conditional version preserved Restore the condition
Closest-file rule No subtree silently governed by a farther file Reconcile or leave deliberately
Resolved version diff No unintended version changes Investigate before merging
Package set Same packages used before and after CPM does not change the set
Workflow from a props and version inventory, through staged centralization of unconditional, differing, conditional, and subtree versions, to a resolved version diff.
Editorial workflow derived from F031 and F032. The sequence describes a reviewable routine; it is not an official migration order.

Working with Claude Code on the migration

Give the agent the repository root and ask for three inventories before any edit: every props file with its coverage, every project-level version with its condition, and every VersionOverride. The agent session works best when the check is a restore plus a resolved-version diff, which is the shape the official best-practices guidance recommends.

Ask the agent to report four things when it finishes. The central entries it added. The overrides it kept and why. The conditions it preserved. The resolved-version diff showing no unintended changes. A report that omits the diff has not finished, because the effective version is the only thing that matters at restore time.

Reviewing the override decisions is the reviewer’s job. The agent reads project files and can run restore, but deciding whether a version difference is intended is a design decision. The Claude Code verification guide covers the review questions: what changed, what proves it, and what was not checked.

Tradeoff between one central version per package and the visibility work needed to keep closest-file rules, overrides, and conditions reviewable.
Editorial tradeoff diagram based on F031 and F032. Centralization is a visibility gain only when the inventory survives the migration.

Data gap and future update

F031 describes default behavior and names manual imports, overrides, and disabled CPM as things that change the effective result. This post does not enumerate every NuGet or SDK version behavior. A future update should record, per repository, which subtrees keep a nested props file, which overrides are deliberate, and the SDK version the observations were taken at.

No benchmark, restore-time measurement, or supply-chain safety claim is made here. The effect of CPM on restore duration or package-source trust is out of scope.

One AI API Key option for OpenAI-format agents

Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.

OpenAI-format agents have a separate route: One AI API Key offers https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. It is a different client and request format, not a workaround for Claude Code authentication. Check the free model list and eligibility notes before choosing an agent route, or read the quickstart for the request shape.

FAQ

Does CPM change which packages my project uses?

No. It changes where the version is written. The PackageReference list stays in the project file and names the same packages; only the version moves to the central PackageVersion entry.

Which props file wins for a project?

By default the closest Directory.Packages.props to the project, as recorded in F031. A parent file needs an explicit import to apply. A migration that edits only the root file can miss a subtree governed by a closer file.

When should I keep a VersionOverride?

When the version difference is intended. VersionOverride is the documented exception mechanism. Keep it deliberately and record why, or reconcile the project to the central version. An override nobody can explain is a finding.

Can central versions vary by target framework?

Yes. Conditional PackageVersion entries select different versions for different conditions, and .NET multi-targeting covers that pattern in detail. Preserve the condition during the migration.

How do I verify the migration did not change effective versions?

Restore before and after and compare the resolved version of every package in the inventory. The concrete win is one place per version; the verification is that the resolved graph matches the intended one.

This post is one of ten build-system and dependency guides written together. .NET Multi-Targeting and C# Source Generators complete the .NET set.

The JVM posts cover version and variant selection: Gradle Constraints vs Dependencies, Gradle Capability Conflicts, Gradle Variant Attributes, and Maven Optional Dependencies.

The C++ posts cover build inputs and dependency boundaries: CMake Presets, CMake find_package vs FetchContent, and Conan CMakeDeps.

More from this batch

More Claude Code troubleshooting

Sources

Control checklist covering props file inventory, version and override inventory, condition preservation, closest-file rule, and resolved version diff.
Editorial control checklist derived from F031 and F032. Passing it shows the migration preserved effective versions; it does not change package-source trust.
Verdict that an inventoried CPM migration keeps effective versions unchanged while giving each package one version home, and that a skipped inventory hides overrides.
Editorial verdict based on F031 and F032. The inventory is the migration; the resolved-version diff is the verification.
More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
Claim $10 credit →