NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 249 forks source link

Uninstalling a nuget package does not remove it from Directory.Packages.props file #13562

Open einsteine89 opened 2 weeks ago

einsteine89 commented 2 weeks ago

NuGet Product Used

Visual Studio Package Management UI, Visual Studio Package Manager Console

Product Version

dotnet 8.0.300, Visual Studio Professional 2022 17.10.0

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

When using Central Package Management with Directory.Packages.props file on solution level, trying to uninstall a package from Visual Studio Package Management UI or via Package Management Console results in the package being removed from all the .csproj files but it still remains in the Directory.Packages.props.

Steps to reproduce:

  1. Create a new dotent 8 Console application
  2. Add the Directory.Packages.props file with this content
    <Project>
    <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
    </PropertyGroup>
    <ItemGroup>
    </ItemGroup>
    <ItemGroup>
    </ItemGroup>
    </Project>
  3. Install any nuget package and see the .csproj and Directory.Packages.props files being updated image
  4. Uninstall the nuget pacakge and see the .csproj file being updated but Directory.Packages.props not image

Verbose Logs

No response

nkolev92 commented 2 weeks ago

This is intentional due to the fact that within the context of a project, we'll never know how many projects the Directory.Packages.props applies to.

There's a related idea that'd prune all the potentially unused package versions: https://github.com/NuGet/Home/issues/9024

nkolev92 commented 2 weeks ago

Team Triage: It is unlikely that we'd add something that prunes package versions by default, as we cannot know for sure that the Directory.Packages.props applies to only the projects within the context we're restoring.

The approach would probably have to be something that the user opts into, such as a commandline argument or an option in the UI.