Skip to content

Restore installs unlisted packages when floating versions such as * are used #10931

Closed

Description

@rainersigwald

Issue moved from dotnet/msbuild#6233


From @MarkKharitonov on Tuesday, March 9, 2021 3:28:08 PM

Issue Description

We have changed the versioning scheme of an internal NuGet package. The new scheme places the new versions below the old ones, so the latter were unlisted from the NuGet repository (we use Azure Artifacts).

The NuGet package is referenced in code using a *, like this - 61.*:

    <PackageReference Include="Company.Payroll.Engine.DB">
      <Version>61.*</Version>
    </PackageReference>

We run msbuild with the RestoreForce = true and msbuild restores the latest old version, which is unlisted.

Note that running nuget.exe list command returns the correct new version, i.e. it does ignore the unlisted versions unlike msbuild.

Steps to Reproduce

  1. Create a NuGet package and publish it to anywhere. I think the server side technology does not matter as long as it supports the NuGet API.
  2. Create an msbuild project and reference the NuGet package using *
  3. Have 2 versions of the NuGet package
  4. Unlist the newest version
  5. run msbuild /t:Restore /p:RestoreForce=true

Expected Behavior

The unlisted package is ignored - the previous package version should be restored instead.

Actual Behavior

The unlisted package is restored. Cleaning the nuget cache does not help.

Analysis

I checked with Fiddler and nuget uses a different API than msbuild. Nuget uses some kind of XML API, whereas msbuild uses JSON API, specifically https://docs.microsoft.com/en-us/nuget/api/package-base-address-resource which I believe is wrong, because it returns both listed and unlisted versions (as documented in the article), without indicating what is unlisted. As such it is not suitable to resolve the * versions. Or any range versions in general.

Versions & Configurations

  • NuGet Version: 5.2.0.6090
  • Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET Framework

Attach a binlog

msbuild.zip

Activity

  1. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @benvillalobos on Wednesday, March 10, 2021 4:19:43 PM

    Team Triage: @nkolev92 is this a NuGet issue?

  2. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @nkolev92 on Wednesday, March 10, 2021 7:51:38 PM

    That's by design.
    Listedness does not affect resolution, only user discoverability (searching for packages on nuget.org, PM UI).

  3. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @MarkKharitonov on Wednesday, March 10, 2021 9:00:50 PM

    I was afraid you would say so. So nuget.exe list would not return delisted versions, but msbuild /restore would happily restore it.
    Now I may understand it when the version is provided exactly. But when it is given as a range - don't you do discovery first? No matter how you call it - the discovery phase is there. You are calling NuGet API to discover the available versions. And if it is by design, then how come the discovery API you use returns delisted versions? By your own words - it should not.

  4. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @nkolev92 on Wednesday, March 10, 2021 10:27:51 PM

    Now I may understand it when the version is provided exactly. But when it is given as a range - don't you do discovery first?

    Exact version is preferred. You'd get a warning if anything else was resolved.

  5. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @MarkKharitonov on Thursday, March 11, 2021 5:07:25 AM

    I would also prefer an exact version. But we use * versions for some of our internal NuGet packages.

    So, back to my question. Given a range of versions - don't you do version discovery? And if so, shouldn't delisted versions be excluded from this discovery?

  6. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @nkolev92 on Thursday, March 11, 2021 5:22:56 PM

    All available versions are considered when using floating versions.
    Once a package has been installed, the notion of a package being listed is lost.

  7. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @MarkKharitonov on Thursday, March 11, 2021 6:21:04 PM

    I am sorry. I still do not understand. We use RestoreForce=true during the restore. That means the version restored an hour ago may not be the version restored now, because the flag forces discovery of the new versions. That discovery happens before the resolution. My point - the discovery should not include delisted versions.

  8. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @nkolev92 on Thursday, March 11, 2021 6:42:59 PM

    My point - the discovery should not include delisted versions.

    Floating versions by design considers listed and unlisted versions.

  9. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @MarkKharitonov on Thursday, March 11, 2021 6:49:11 PM

    Is it documented anywhere?

  10. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @nkolev92 on Thursday, March 11, 2021 7:10:19 PM

    Docs available here: https://docs.microsoft.com/en-us/nuget/nuget-org/policies/deleting-packages

    I couldn't find the client side one, I created an issue for that to be added there as well, https://github.com/NuGet/docs.microsoft.com-nuget/issues/2349.

  11. rainersigwald commented on Jun 9, 2021

    @rainersigwald
    Author

    Issue moved from dotnet/msbuild#6233


    From @MarkKharitonov on Thursday, March 11, 2021 8:28:59 PM

    Now that I know it is by design I question - why do we need package delisting at all? Seems like actually deleting the package is the only way to affect the floating versions algorithm.

    I think this design is flawed.

  12. changed the title [-]msbuild restores delisted NuGet package versions when PackageReferenve.Version ends with * to denote the latest version[/-] [+]Restore installs unlisted packages when floating versions such as `*` are used[/+] on Jun 16, 2021
  13. nkolev92 commented on Jun 16, 2021

    @nkolev92
    Member

    Hey @MarkKharitonov,

    As mentioned before, this was a conscious made by the NuGet team for floating versions. The concept of listed/unlisted packages is a discoverability concern.

  14. added
    Type:DCR
    Priority:3
    on Jun 16, 2021
  15. MarkKharitonov commented on Jun 16, 2021

    @MarkKharitonov

    Using a floating version with the RestoreForce flag requires you to first discover the packages matching the criteria. Why you do not consider this action as the discovery phase?
    I am sorry, but I just do not understand how nuget restore and msbuild restore returning different versions on the same floating version makes sense to you guys.

  16. nkolev92 commented on Jun 16, 2021

    @nkolev92
    Member

    nuget restore and msbuild restore should not have a different behavior. They are running the exact same code.

  17. MarkKharitonov commented on Jun 16, 2021

    @MarkKharitonov

    Sorry, nuget list - the discovery command. What I should have written is that I do not understand how the discovery performed by nuget list should be different from that by msbuild restore when we are talking about a floating version.

  18. zkat commented on Jul 12, 2021

    @zkat
    Contributor

    Closing by design. Unlisted packages are not meant to be discoverable, however, we made a conscious decision to include them for floating packages to avoid breaking people who were relying on those packages already.

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

    Functionality:RestorePriority:3Style:PackageReferenceType:DCR

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions