Search code examples
c#visual-studionuget

Unable to get Central Package Management (CPM) to work as expected


Just in the process of converting our legacy application (.NET 4.8) to use Central Package Management instead of the individual packages.json files.

I used the .NET Upgrade Assistant for most of the heavy lifting.

Everything appears to have worked correctly. I see the Directory.Packages.props has been generated in the root (same directory as the solution) of the repository.

All projects (.csproj) now have the their correct PackageReference's, e.g.,

<ItemGroup>
    <PackageReference Include="System.ValueTuple" />
</ItemGroup>

The generated Directory.Packages.props has the following structure:

<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    <CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
  </PropertyGroup>
  </ItemGroup>
    <PackageVersion Include="System.ValueTuple" Version="4.5.0" />
    ...Many other package versions
  </ItemGroup>
</Project>

Problem

Anytime I add a new Nuget package in Visual Studio via VS Package Manager UI, that package is not being added to the Directory.Packages.props file. Furthermore the individual PackageReference added to the project (.csproj) contain a version.

<PackageReference Include="Humanizer">
    <Version>2.14.1</Version>
</PackageReference>

I'm unsure why this new package is not being added to the Directory.Packages.props file and I also don't understand why the package is being added to the .csproj with a version.

We're using the following versions:

  • Visual Studio 2022 Enterprise v17.11.2
  • Nuget 6.11.0
  • Installed dotnet version: 8.0.400

All of our C# projects are targeting .NET Framework 4.8.


Solution

  • Unfortunately at the time of this writing (2025-02-24) Central Package Management (CPM) does not support the old style csproj, so in essence .NET Framework projects are not supported.

    [Feature]: Add support for central package management to Visual Studio Package Manager UI for legacy projects