Central Package Management in .NET — Simplifying Dependencies the Smart Way

Morteza JangjooMorteza Jangjoo
3 min read

Managing NuGet package versions across multiple projects in a solution can quickly become a pain — especially as the number of projects grows. With the introduction of Central Package Management (CPM) in .NET SDK-style projects, developers can now streamline their dependency management with ease and consistency.

In this post, we’ll explore what Central Package Management is, how to enable it using the ManagePackageVersionsCentrally feature, and why it matters in large-scale solutions.


🚀 What Is Central Package Management?

Central Package Management allows you to define NuGet package versions in a single file (Directory.Packages.props) and reference those packages in individual projects without specifying versions repeatedly.

This eliminates version mismatches, simplifies upgrades, and improves maintainability across solutions with many .csproj files.


🧠 Why Use It?

Here are a few solid reasons to consider Central Package Management:

Consistency — One version per package across your entire solution
Simpler .csproj files — No need to repeat version numbers
Easier upgrades — Change the version in one place
Avoids version conflicts — Keeps dependency graph clean and predictable
Cleaner diffs in Git — Especially when updating packages


🔧 How to Enable Central Package Management

To start using this feature, follow these steps:

1. ✅ Create Directory.Packages.props

In the root of your solution (or a directory common to multiple projects), create a new file named Directory.Packages.props:

<Project>
  <ItemGroup>
    <PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageVersion Include="Serilog" Version="2.12.0" />
  </ItemGroup>
</Project>

This defines the versions of packages to be used centrally.


2. ✅ Update Your Project Files (.csproj)

Inside your individual project files, simply reference the packages without specifying a version:

<ItemGroup>
  <PackageReference Include="Newtonsoft.Json" />
  <PackageReference Include="Serilog" />
</ItemGroup>

That’s it. The version will now be resolved from Directory.Packages.props.


3. ✅ (Optional) Set the Feature Flag

If you're using a version of .NET SDK prior to .NET 6, you might need to explicitly enable central version management by adding the following line to your .csproj:

<PropertyGroup>
  <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

In .NET 6 and newer, this flag is automatically respected when Directory.Packages.props is present.


🧪 Sample Project Structure

MySolution/
├── Directory.Packages.props
├── ProjectA/
│   └── ProjectA.csproj
└── ProjectB/
    └── ProjectB.csproj

Both ProjectA and ProjectB use the same version of packages defined centrally.


⚠️ Important Notes

  • Central Package Management works only with SDK-style projects (.NET Core, .NET 5+, .NET Standard)

  • It does not support projects that still use packages.config

  • Visual Studio 2022+ and .NET CLI fully support this feature


🧩 Bonus: Overriding Central Version (If Needed)

If you really need to override a version in a specific project (not recommended unless necessary), you can still do it by adding the Version attribute back in the .csproj:

<PackageReference Include="Serilog" Version="2.11.0" />

The local version will override the central one — but use this carefully to avoid inconsistency.


✅ Final Thoughts

Central Package Management is one of those underrated features in .NET that can greatly improve the cleanliness and maintainability of your codebase, especially in microservice or multi-project solutions.

If you're still manually managing versions across multiple .csproj files, now is a great time to centralize and simplify.


📚 Resources:


I’m Morteza Jangjoo and “Explaining things I wish someone had explained to me”

0
Subscribe to my newsletter

Read articles from Morteza Jangjoo directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Morteza Jangjoo
Morteza Jangjoo