Skip to content

Restore output collection probes package metadata for project references #15155

Open
NuGet/NuGet.Client
#7904

Description

@patschaefer

NuGet Product Used

NuGet.exe, MSBuild.exe

Product Version

Observed with NuGet 6.13 during MSBuild restore on Windows. The same unfiltered loop is present in NuGet.Client dev at commit 0d428c0305148200b0a6f20fe4065e5bb58f3fdb.

Worked before?

No

Impact

It's more difficult to complete my work

Repro Steps & Context

NoOpRestoreUtilities.GetRestoreOutput iterates every entry in lockFile.Libraries and passes its name and version to GetPackageFiles, without filtering by library type. This includes entries explicitly marked type: project.

GetPackageFiles then checks for <id>.<version>.nupkg.sha512 and, if absent, .nupkg.metadata under the global-packages directory and configured fallback folders.

Public source:

Minimal scenario for reproducing the probes

The names below are synthetic. A demand-loaded filesystem is not required to inspect the unnecessary probes.

  1. Create two SDK-style class-library projects, ProbeConsumer and ProbeLibrary, with a ProjectReference from the consumer to the library. Set the library's <Version> to 2.3.4. Do not add a package dependency named ProbeLibrary.

  2. Force a restore of the consumer with a dedicated global-packages directory:

    dotnet restore .\ProbeConsumer\ProbeConsumer.csproj --force --packages .\probe-packages
  3. Confirm that the consumer's project.assets.json contains ProbeLibrary/2.3.4 with "type": "project".

  4. Trace filesystem operations during restore, or instrument/break in GetPackageFiles. The unfiltered loop passes the project identity to the package-marker checks, producing probes for:

    <global-packages>\probelibrary\2.3.4\probelibrary.2.3.4.nupkg.sha512
    <global-packages>\probelibrary\2.3.4\.nupkg.metadata
    

The command above is a suggested standalone reproduction; the observed behavior was diagnosed in a larger restore and corroborated by the source path.

Expected behavior

Only package libraries should enter this package-marker collection loop. Project-reference libraries should not cause checks for package installation metadata. Existing handling of PackageDownload dependencies should remain unchanged.

Actual behavior and impact

Project-reference identities are also probed. On an ordinary local disk, missing markers are inexpensive. On a demand-loaded global-packages filesystem, these lookups can require remote work. In our read-through implementation, they can trigger unnecessary package acquisition, extraction, and publication when a project name/version happens to match a real feed package. Missing identities can also incur repeated remote lookup costs.

To be clear, NuGet is performing filesystem existence checks, not explicitly downloading project references. The acquisition side effect comes from the demand-loaded filesystem, and we have not observed project references being replaced by packages in dependency resolution. We have not quantified the overall restore-time improvement from removing these probes.

Suggested change

Filter the lockFile.Libraries loop in GetRestoreOutput to package libraries. Is there a compatibility reason for including project libraries here?

A regression test should cover a project library whose name/version also has package-marker files on disk, verifying that those markers are excluded while actual package libraries and PackageDownload dependencies remain included.

Related but distinct: NuGet/Home#14963 and NuGet.Client#7569 concern scanning other versions of actual packages, rather than probing project-reference identities.

Verbose Logs

No public trace attached. The relevant source path and synthetic reproduction scenario are provided above.

Activity

  1. jebriede commented on Nov 20, 2026

    @jebriede
    Contributor

    I reproduced this locally: restore checks for a .nupkg.sha512 file matching a project reference and records it in project.nuget.cache, even though project.assets.json identifies the reference as a project.

  2. patschaefer commented on Nov 20, 2026

    @patschaefer
    Author

    I will raise a PR with a fix. I'm validating it now.

  3. added
    Tenet:Performance
    Priority:3
    on Nov 23, 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:3Tenet:PerformanceType:Bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions