You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Restore installs unlisted packages when floating versions such as * are used #10931
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.*:
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
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.
Create an msbuild project and reference the NuGet package using *
Have 2 versions of the NuGet package
Unlist the newest version
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
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.
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?
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.
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.
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
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.
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.
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.
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.
Activity
rainersigwald commentedon Jun 9, 2021
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?
rainersigwald commentedon Jun 9, 2021
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).
rainersigwald commentedon Jun 9, 2021
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.
rainersigwald commentedon Jun 9, 2021
Issue moved from dotnet/msbuild#6233
From @nkolev92 on Wednesday, March 10, 2021 10:27:51 PM
Exact version is preferred. You'd get a warning if anything else was resolved.
rainersigwald commentedon Jun 9, 2021
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?
rainersigwald commentedon Jun 9, 2021
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.
rainersigwald commentedon Jun 9, 2021
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.
rainersigwald commentedon Jun 9, 2021
Issue moved from dotnet/msbuild#6233
From @nkolev92 on Thursday, March 11, 2021 6:42:59 PM
Floating versions by design considers listed and unlisted versions.
rainersigwald commentedon Jun 9, 2021
Issue moved from dotnet/msbuild#6233
From @MarkKharitonov on Thursday, March 11, 2021 6:49:11 PM
Is it documented anywhere?
rainersigwald commentedon Jun 9, 2021
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.
rainersigwald commentedon Jun 9, 2021
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.
[-]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[/+]nkolev92 commentedon Jun 16, 2021
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.
MarkKharitonov commentedon Jun 16, 2021
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 restoreandmsbuild restorereturning different versions on the same floating version makes sense to you guys.nkolev92 commentedon Jun 16, 2021
nuget restoreandmsbuild restoreshould not have a different behavior. They are running the exact same code.MarkKharitonov commentedon Jun 16, 2021
Sorry,
nuget list- the discovery command. What I should have written is that I do not understand how the discovery performed bynuget listshould be different from that bymsbuild restorewhen we are talking about a floating version.zkat commentedon Jul 12, 2021
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.