Managing packages in a .NET solution with many projects can be tricky. If you’ve worked on large applications with dozens or even hundreds of projects, you’ve likely seen problems such as:
- Version mismatches: Projects using different versions of the same NuGet package.
- Manual work: Having to update each .csproj file one by one.
- Build failures: CI/CD pipelines breaking because package versions don’t match.
To make this easier, Microsoft introduced Central Package Management (CPM) in .NET, starting with NuGet 6.0 and SDK-style projects.
What is Central Package Management?
Central Package Management lets you keep all NuGet package versions in one central file for your solution. Instead of writing the version number in every project file, you set it once in a file called Directory.Packages.props, and all projects use that version.
This makes upgrades easier, keeps versions consistent, and reduces maintenance work.
How It Works
-
Create a central file:
At the solution’s root, add a file named Directory.Packages.props.
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="RabbitMQ.Client" Version="7.1.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="9.0.3" />
</ItemGroup>
</Project>
![Central Package Management]()
2. Reference packages in projects (without specifying versions):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
<PackageReference Include="RabbitMQ.Client" />
</ItemGroup>
</Project>
![Central Package Management]()
Note: The project file doesn’t include a version number. Instead, the version is defined in Directory.Packages.props.
3. Automatic adoption:
The .NET SDK automatically finds the Directory.Packages.props file in your solution folder and applies it to all projects.
Benefits of Central Package Management
- Consistency – Every project uses the same package version, avoiding conflicts.
- One place to update – Change the version in a single file instead of many.
- Fewer code conflicts – No version mismatches in .csproj files.
- Reliable builds – CI/CD pipelines run more smoothly.
- Simpler project files – .csproj files stay clean and easy to read.
Here’s a simpler example with different packages:
Suppose you have a solution with 15 projects, all using Newtonsoft.Json. Without CPM, updating it means changing 15 .csproj files.
With CPM, you just add this to Directory.Packages.props:
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
Now all projects use the new version automatically.
Conclusion
Central Package Management (CPM) in .NET makes life easier for teams working on solutions with many projects. It keeps package versions consistent, simplifies updates, and saves time.
If you haven’t tried it yet, create a Directory.Packages.props file in your solution—you’ll quickly see the advantages.
Happy Coding!