It can be challenging to manage packages in a.NET solution with numerous projects.  You've probably seen issues like this if you've worked on big apps with dozens or even hundreds of projects.

  • Projects utilizing various iterations of the same NuGet package are known as version mismatches.
  • Manual labor: Each must be updated. csproj files one after the other.
  • Build failures: CI/CD pipelines malfunctioning due to mismatched package versions.

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!

HostForLIFE ASP.NET Core 9.0 Hosting

European Best, cheap and reliable ASP.NET hosting with instant activation. HostForLIFE.eu is #1 Recommended Windows and ASP.NET hosting in European Continent. With 99.99% Uptime Guaranteed of Relibility, Stability and Performace. HostForLIFE.eu security team is constantly monitoring the entire network for unusual behaviour. We deliver hosting solution including Shared hosting, Cloud hosting, Reseller hosting, Dedicated Servers, and IT as Service for companies of all size.