Skip to content

🐛 Pinned-Dependencies: keep scanning Directory.*.props until central package management is found - #5348

Open
jeffersonnlucas wants to merge 1 commit into
ossf:mainfrom
jeffersonnlucas:fix/nuget-cpm-directory-props
Open

jeffersonnlucas wants to merge 1 commit into
ossf:mainfrom
jeffersonnlucas:fix/nuget-cpm-directory-props

Conversation

@jeffersonnlucas

@jeffersonnlucas jeffersonnlucas commented Oct 19, 2026 •

Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix.

What is the current behavior?

processDirectoryPropsFile stores the first well-formed Directory.*.props it sees and returns false (stop iterating), regardless of whether that file enables central package management.

In the layout the NuGet docs recommend, a repository has both Directory.Build.props (shared build settings, no ManagePackageVersionsCentrally) and Directory.Packages.props (CPM). Both match Directory.*.props, and Directory.Build.props is listed first by the tarball handler and by filepath.Walk in the local client. The check therefore records IsCPMEnabled: false, falls back to the per-csproj RestoreLockedMode path, and reports every dotnet restore / nuget restore as unpinned with the generic remediation, even when every PackageVersion is fixed.

Observed on https://scorecard.dev/viewer/?uri=github.com/aedis-build/aedis-dotnet (root Directory.Build.props + Directory.Packages.props with CPM enabled): nugetCommand not pinned by hash ... enabling central package management ... for all three restore commands.

What is the new behavior (if this is a feature change)?

While the parsed file does not enable CPM, keep iterating so Directory.Packages.props is reached. The first file that enables CPM is still the one used, as before.

  • Tests for the changes have been added (for bug fixes/features)

TestProcessDirectoryPropsFileKeepsSearchingUntilCPMIsEnabled feeds a props file without CPM followed by one with CPM, using the existing testdata; it fails on main and passes with this change. TestAnalyseCentralPackageManagementPinned is unchanged and still passes (a file without CPM now leaves CpmConfig at its zero value, which the test already expects).

Which issue(s) this PR fixes

Fixes #5349

Special notes for your reviewer

Not covered here, on purpose: repositories with several Directory.Packages.props (one per sub-tree) still only use the first one found. That is the pre-existing behavior and a separate change.

Does this PR introduce a user-facing change?

Pinned-Dependencies: NuGet central package management is now detected when a Directory.Build.props is listed before Directory.Packages.props.

…package management is found

processDirectoryPropsFile stored the first well-formed Directory.*.props and stopped
iterating, even when that file did not enable central package management. In the
layout the NuGet docs recommend, Directory.Build.props (build settings, no CPM) sorts
before Directory.Packages.props, so CPM was never detected and every nuget restore
command was reported unpinned with the generic remediation.

Keep iterating while the file does not enable CPM, so Directory.Packages.props is
reached.

Signed-off-by: Jeffersonn Barboza <jeffersonnlucas@gmail.com>

This branch has not been deployed

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

BUG: Pinned-Dependencies ignores NuGet central package management when Directory.Build.props is listed before Directory.Packages.props

1 participant