Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nuget Central Package Management cannot update versions in imported "Directory.Packages.props" files with non-default name #9351

Open
jebriede opened this issue Dec 7, 2023 · 3 comments
Assignees
Labels
Bug This is a functional issue in already written code. Triage-Investigate Reviewed and investigation needed by dev team
Milestone

Comments

@jebriede
Copy link

jebriede commented Dec 7, 2023


Issue moved from NuGet/Home#13041


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

@jebriede
Copy link
Author

jebriede commented Dec 7, 2023


Issue moved from NuGet/Home#13041


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.

@adamint
Copy link
Member

adamint commented Dec 14, 2023

@drewnoakes do we own the behavior associated with updating these files after a package manager modification? If so, could you share the codepath.

@tmeschter tmeschter self-assigned this Jan 11, 2024
@tmeschter tmeschter added the Bug This is a functional issue in already written code. label Jan 11, 2024
@tmeschter tmeschter added this to the 17.10 milestone Jan 11, 2024
@drewnoakes drewnoakes added the Triage-Investigate Reviewed and investigation needed by dev team label Jan 18, 2024
@cakirpro
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a functional issue in already written code. Triage-Investigate Reviewed and investigation needed by dev team
Projects
None yet
Development

No branches or pull requests

5 participants