dotnet / project-system

The .NET Project System for Visual Studio
MIT License
969 stars 387 forks source link

Removing reference from project does not remove it from the dependencies tree #6813

Closed drewnoakes closed 3 years ago

drewnoakes commented 3 years ago

Visual Studio Version: Version 16.9.0 Preview 3.0 [30904.159.main]

(Moved from AB#1257238)

Likely a result of recent dependency tree changes.

Repro steps:

  1. Create project
    <Project Sdk="Microsoft.NET.Sdk">
     <PropertyGroup>
       <TargetFramework>netcoreapp3.1</TargetFramework>
     </PropertyGroup>
     <ItemGroup>
       <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
     </ItemGroup>
    </Project>
  2. Manually remove the PackageReference item and save the project
  3. The item is still visible in the dependencies tree image

This doesn't happen for assembly references.

AraHaan commented 3 years ago

does it get removed when you use dotnet restore on the command line and then reloading the project itself?

drewnoakes commented 3 years ago

The bug is in VS. Removing the item from the project updates the project.assets.json file correctly.

drewnoakes commented 3 years ago

Reloading the project in VS fixes it too.

AraHaan commented 3 years ago

How about have it automatically reload the project every time the project system updates that json file?

drewnoakes commented 3 years ago

VS monitors that file. The bug is localised to the code that manages the tree. It isn't responding to the change notification correctly.

drewnoakes commented 3 years ago

I have a fix for this. Will spend a little time tomorrow to tidy up some of the code around this area, as the fix on its own is very cryptic, and I think the class can be made more straightforward.