Skip to content

Rerunning 'dotnet add package ...' creates duplicate in non-SDK #8561

Open

Description

@centreboard

Details about Problem

NuGet product used (dotnet.exe):

dotnet.exe --version:
Both 2.2.103 and 3.0.100-preview9-014004

OS version:
win10 1903

Worked before? If so, with which NuGet version:
Works in SDK projects and through Rider and VS UI

Detailed repro steps so we can see the same problem

  1. For a non-SDK project using PackageReferences and containing
    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />

  2. Run dotnet add package Newtonsoft.Json to update to 12.0.2

  3. Project now contains a new entry instead of updating the reference

    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
  1. Run dotnet add package Newtonsoft.Json again, another entry is added
    <PackageReference Include="Newtonsoft.Json" Version="11.0.1" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
    <PackageReference Include="Newtonsoft.Json" Version="12.0.2" />

Other suggested things

Sample non-SDK Project

ClassLibrary1.zip

Activity

  1. added this to the Backlog milestone on Sep 17, 2019
  2. rrelyea commented on Sep 17, 2019

    @rrelyea
    Contributor

    yes, this repros with .net core 3.0.0-preview9 (and maybe 2.x? 1.x?)
    whether you specify a version or not, it adds a new entry (even if you choose the same version).

    Note...the new tag also seems to add with an attribute...which isn't legal in old csproj files - project system doesn't support it.

    Would love to understand if this works with 2.x or 1.x.
    Would be more interested in fixing sooner if it was a regression...but my guess is that this has always been broken...

  3. PeteBoyRocket commented on Mar 20, 2020

    @PeteBoyRocket

    Just come across this issue with a web project. I assume the only workaround right now is to ALWAYS do dotnet remove package first, then dotnet add package?

  4. added
    Priority:2
    Category:Quality Week
    on Apr 30, 2020
  5. Saibamen commented on May 24, 2022

    @Saibamen

    Just come across this issue with a web project. I assume the only workaround right now is to ALWAYS do dotnet remove package first, then dotnet add package?

    This is probably the only workaround

  6. zivkan commented on May 26, 2022

    @zivkan
    Member

    Team triage meeting: non-SDK projects are not intended to be supported by the dotnet cli. We should check if there's an easy way for us to detect if the project is SDK or not, and error out, rather than adding a duplicate (probably less effort than actually fixing the issue)

  7. Saibamen commented on May 27, 2022

    @Saibamen

    Error?

    What about currently used scripts in CI pipelines?
    Please make it as warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Category:Quality WeekPriority:2Product:dotnet.exeType:Bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions