Nuget Central Package Management cannot update versions in imported "Directory.Packages.props" files with non-default name
Issue moved from NuGet/Home#13041
- Please respond to @WolfgangHG.
From @WolfgangHG on Saturday, November 25, 2023 9:20:13 AM
NuGet Product Used
Visual Studio Package Management UI
Product Version
"nuget.exe" reports 6.8.0.122
Worked before?
No response
Impact
It bothers me. A fix would be nice
Repro Steps & Context
While experimenting with CPM, I first tried something similar to this rather weird structure of nuget CPM declarations:
In the solution root, there sits a "Directory.Packages.props" file that imports a file "Included_Directory.Packages.props".
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<Import Project=".\Included_Directory.Packages.props" />
<ItemGroup>
<!--Additional package versions -->
</ItemGroup>
</Project>
This file "Included_Directory.Packages.props" defines a version for "Newtonsoft.Json":
<Project>
<ItemGroup>
<PackageVersion Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
</Project>
The projects declare a package reference:
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>
When using Nuget Package Manager to update "Newtonsoft.Json", it does not update the version in "Included_Directory.Packages.props" but overwrites the version in each project file:
<ItemGroup>
<PackageVersion Update="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
See attached sample (with original state - you have to update "Newtonsoft.Json" to reproduce the problem): NugetCPM_NonDefault.zip
My reason for doing something like this: I have a rather large tools solution with a lot of utility dlls, and I have an application that references those utility dlls (by including copies of the tools dll in a local folder and referencing those dlls instead of using Nuget package references - due to historical reasons :-( ). So I want to copy the "Directory.Packages.props" from the utility solution to the application solution with a different name, and import it in the application solution "Directory.Packages.props". When updating a nuget package, VS would modify each project file instead of trying to write to the imported "Directory.Packages.props".
It works when the imported file has the name "Directory.Packages.props" and is just placed in a subdir. So, this would be the workaround for me. Here is a sample with this workaround: NugetCPM_Default.zip
Verbose Logs
No response
Issue moved from NuGet/Home#13041
- Please respond to @amis92.
From @amis92 on Tuesday, November 28, 2023 9:20:04 PM
I recently also had a similar problem, but I've followed the documentation at https://learn.microsoft.com/en-us/nuget/consume-packages/central-package-management to create a repository-level /Directory.Packages.props, and test-projects-only /test/Directory.Packages.props which imported the root one.
I didn't have much time so I just used a single root file, but that documented scenario didn't work for me and I think it might be associated/the same issue.
@drewnoakes do we own the behavior associated with updating these files after a package manager modification? If so, could you share the codepath.
Same problem, can easily be reproduced for example by updating the package using the Nuget Packages window (Manage Packages for Solution) in Visual Studio 2022 17.8.5.