Skip to content

NuGet is restoring packages from feeds that are not configured #14974

Closed
NuGet/NuGet.Client
#7569

Description

@stevendarby

NuGet Product Used

MSBuild.exe

Product Version

.NET SDK:
Version: 10.0.301
Commit: 96856fd726
Workload version: 10.0.300-manifests.8c7d7c03
MSBuild version: 18.6.4+96856fd72

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.301\

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

  1. Create two nuget feeds, e.g. in Azure DevOps, named something like MyFeedA and MyFeedB
  2. Publish MyPackage 1.0.0 to MyFeedA
  3. Publish MyPackage 1.1.0 to MyFeedB (note: same name, different version, different feed)
  4. Create a new solution with ProjectA and a directory nuget.config which clears existing package sources and only pulls from MyFeedA.
  5. Add a reference to MyPackage 1.0.0 in ProjectA. Build in VS.
  6. Separate directory: create a new solution with ProjectB and a directory nuget.config which clears existing package sources and only pulls from MyFeedB.
  7. Add a reference to MyPackage 1.1.0 in ProjectB. Build in VS.
  8. Return to ProjectA and update the version to 1.0.1. (note: this version doesn't exist, it's a way to trigger the particular error message through which I discovered this bug). Build in VS.

warning NU1603: ProjectA depends on MyPackage (>= 1.0.1) but MyPackage 1.0.1 was not found. MyPackage 1.1.0 was resolved instead.

The bug here is that it's resolved a package from a feed that it shouldn't consider or even be aware of. I'm wondering if the fundamental issue here is that locally cached nuget packages are not properly sorted/isolated by the feed?

Verbose Logs


Activity

  1. Nigusu-Allehu commented on Jul 2, 2026

    @Nigusu-Allehu
    Member

    Thanks for the detailed repro.

    One likely explanation is that MyPackage 1.1.0 was downloaded during your earlier restore (for the other solution+feed), and then the later restore reused that same version from the machine’s Global Packages Folder (GPF).

    Could you please confirm whether MyPackage 1.1.0 already exists in your machine’s GPF?
    If it is present there, NuGet may satisfy restore from the GPF.

    Also, a quick clarification: <clear /> under packageSources only clears configured source entries for that property.

  2. added
    WaitingForCustomer
    and removed on Jul 2, 2026
  3. stevendarby commented on Jul 2, 2026

    @stevendarby
    Author

    I will confirm tomorrow but unless I've misunderstood you, that's exactly what I think the bug is. I don't think it should be able to do that; locally the cached feed packages should be separated by the feed id too.

    And yep, clear is at the top of the package sources for both configs.

  4. added
    WaitingForClientTeam
    and removed
    WaitingForCustomer
    on Jul 2, 2026
  5. added
    WaitingForCustomer
    and removed
    WaitingForClientTeam
    on Jul 2, 2026
  6. stevendarby commented on Jul 7, 2026

    @stevendarby
    Author

    @Nigusu-Allehu any response? Problem is precisely when I have the packages cached locally.

  7. added
    WaitingForClientTeam
    and removed
    WaitingForCustomer
    on Jul 7, 2026
  8. Nigusu-Allehu commented on Jul 7, 2026

    @Nigusu-Allehu
    Member

    There are multiple layers of caching. The global packages folder is where installed packages are stored. It allows better performance as you can imagine. FYI, you can override the folder path using NUGET_PACKAGES env variable..

    Thinking about your proposal to have the GPF segregated by sources. We would have to come up with a rule that says: If a package PackageA@Version is downloaded from Source1, only restores that configure Source1 can use the package. With that rule in place there is a couple of things we would have to think about

    • If I am using PackageA@Version in a different project but my project configures source2 not source1, I can't use the local package now because of the above rule. I would have to make an http request and download the package again. That is inefficient.
    • If there are n number of package sources that contain a package PackageA, we would have to download and store PackageA in the GPF n times. That is storage inefficient.
  9. added
    Type:DCR
    and removed
    WaitingForClientTeam
    on Jul 7, 2026
  10. added
    WaitingForCustomer
    on Jul 7, 2026
  11. baronfel commented on Jul 7, 2026

    @baronfel

    Are packages content-hash aware? If so, I could imagine a world where the per-source 'package folders' were populated by symlinks to same-content packages with zero additional download times or local file system size costs?

  12. removed
    WaitingForCustomer
    on Jul 9, 2026
  13. nkolev92 commented on Jul 9, 2026

    @nkolev92
    Member

    I'll try to answer as many of the questions as possible:

    • There is an implicit expectation of package id/version to be globally unique, across different sources. If you trust the sources you have defined, then you should have no concerns here.
    • Package source mapping allows you to define where a package comes from, but that only applies when downloaded. Post download, there's no validation, there's an issue that I just moved to a public location at Validate the source of a package matches the configuration at restore time #14986.

    Beyond that, to answer @baronfel's question, the global packages folder does have the content hash of the package, so if we were to switch the global packages folder to a per source location, we could theoretically use that to dedup.

    As far as options for today, you can redirect the global packages folder to a repo local location, and in combination with package source mapping you should get an experience that's extremely close to what you're looking for right now.

    We'll retitle this issue to refer to the global packages folder format and leave it open to get feedback:
    In practice this could look something like:

    gpf/sourcea/package/1.0.0 instead of gpf/packagea/1.0.0

  14. changed the title [-]NuGet is restoring packages from feeds that are not configured[/-] [+]global packages folder should have a per source package copy[/+] on Jul 9, 2026
  15. added
    Priority:3
    on Jul 9, 2026
  16. zivkan commented on Jul 28, 2026

    @zivkan
    Member

    I think the NuGet team misread this issue. The repro steps can be boiled down to: pre-populate the global packages folder with different versions of a package, then reference a version higher than what exists in the package source, but lower than what exists in the global packages folder, and NuGet will select the version from the GPF, even though the package source knows nothing about it.

    This means that cleaning the GPF and then running restore again will have different results, which is a violation of NuGet's intent to be reproducible/deterministic.

    The good news is that NuGet/NuGet.Client#7569 already fixes the problem, so the bug reported will be fixed in .NET 11.0.100 and VS 18.10. This issue's title has been renamed to a different scenario, so I'm not sure if the issue should be kept open for that scenario (even though it's different to the repro steps), or if the issue should be closed, since the repro steps will no longer be possible once the PR's fix ships.

  17. changed the title [-]global packages folder should have a per source package copy[/-] [+]NuGet is restoring packages from feeds that are not configured[/+] on Jul 28, 2026
  18. nkolev92 commented on Jul 28, 2026

    @nkolev92
    Member

    Thanks @zivkan, great point.

    We'll close this issue as fixed by 7569 and I have reopened #15011 for the other topic.

  19. added this to the 7.10 milestone on Sep 10, 2026
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:3Type:DCR

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions