Managing NuGet packages across multiple projects can get messy fast.
If you’ve ever had to update the same package version in 10 different .csproj
files, you know the pain.
Luckily, .NET now supports Central Package Management — a feature that simplifies your life by defining package versions in a single place using Directory.Packages.props
.
Let’s dive into how this works and why you should use it.
🧠 What is Central Package Management?
Central Package Management (CPM) allows you to manage all your NuGet package versions in one file.
Instead of defining the package version in every project, you define it centrally, and each project just references the package name.
No more version mismatch errors. No more tedious updates.
🧰 Benefits at a Glance
- ✅ Consistent package versions across projects
- ✅ Easier upgrades — change one file instead of many
- ✅ Cleaner
.csproj
files - ✅ Fewer merge conflicts in Git
- ✅ Less chance of breaking your solution by mistake
🛠️ How to Use It
1. Create Directory.Packages.props
Add a new XML file in your solution root (or shared folder) and call it Directory.Packages.props
:
<Project>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.1" />
<PackageVersion Include="Serilog" Version="2.12.0" />
</ItemGroup>
</Project>
`
This file will act as the central source of truth for package versions.
2. Update Your .csproj
Files
In each project, reference the package like this:
xml
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="Serilog" />
</ItemGroup>
❌ No version needed here — it's pulled automatically from the central file.
3. (Optional) Enable the Feature Flag
If you're on older SDKs (prior to .NET 6), you might need to enable central management explicitly:
xml
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
For .NET 6+, this is automatic when the Directory.Packages.props
file is present.
🔍 Folder Structure Example
MySolution/
├── Directory.Packages.props
├── ProjectA/
│ └── ProjectA.csproj
└── ProjectB/
└── ProjectB.csproj
Both ProjectA
and ProjectB
now use the same package versions centrally defined.
⚠️ Good to Know
- Only works in SDK-style projects
- Not compatible with
packages.config
- Supported in Visual Studio 2022+ and .NET CLI
- You can override a version locally, but avoid doing this unless necessary
xml
<PackageReference Include="Serilog" Version="2.11.0" />
🧩 Real-World Scenario
Let’s say you want to update Newtonsoft.Json
from 13.0.1
to 13.0.3
.
With Central Package Management:
➡️ Change it once in Directory.Packages.props
— done.
Without it:
❌ Change it in every .csproj
file manually... and pray you don’t miss one.
✅ Conclusion
Central Package Management is a simple but powerful way to reduce friction when working with NuGet dependencies in multi-project .NET solutions.
If you're building anything serious in .NET, give it a try — your future self will thank you.
🔗 Resources
- 📘 Official Microsoft Docs
- 💬 Got questions? Drop a comment below and let’s talk!
💡 Follow me for more .NET and dev productivity tips!
📖 Originally published on my blog
This article was originally published on my personal blog at:
👉 Hashnode Blog: Central Package Management in .NET
There you'll find more deep dives, diagrams, and code samples related to modern .NET development.
I’m Morteza Jangjoo and “Explaining things I wish someone had explained to me”
Top comments (0)