Skip to content

fix: NU1004 false positive when P2P has no compatible TFM in locked mode#7198

Open
PHILLIPS71 wants to merge 2 commits intoNuGet:devfrom
PHILLIPS71:fix/nu1004-p2p-incompatible-tfm-locked-mode
Open

fix: NU1004 false positive when P2P has no compatible TFM in locked mode#7198
PHILLIPS71 wants to merge 2 commits intoNuGet:devfrom
PHILLIPS71:fix/nu1004-p2p-incompatible-tfm-locked-mode

Conversation

@PHILLIPS71
Copy link
Copy Markdown

Bug

Fixes: NuGet/Home#12010

Description

IsLockFileValid unconditionally invalidated the lock file (NU1004) whenever a P2P project had no compatible target framework.

This was incorrect, restore itself produces zero transitive dependencies for such a P2P, so a lock file entry with empty deps is consistent with what restore would produce and should be accepted as valid.

The fix guards the invalidation on whether the lock file entry contains any dependencies:

  • Empty deps: valid; no NU1004 raised.
  • Non-empty deps invalid; the entry is stale from when the P2P previously had a compatible TFM.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@PHILLIPS71 PHILLIPS71 requested a review from a team as a code owner March 7, 2026 00:00
@dotnet-policy-service dotnet-policy-service bot added the Community PRs created by someone not in the NuGet team label Mar 7, 2026
@PHILLIPS71
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

// When no compatible TFM is found, restore contributes no transitive dependencies
// for this P2P project. Non-empty deps in the lock file indicate a stale entry
// from when the P2P previously had a compatible TFM.
if (projectDependency.Dependencies.Count > 0)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @PHILLIPS71

Thanks for creating this PR.

I'm not sure I agree with your assessment that this is a false positive, but I'll check with some of my teammates as well.

I think it's fine if NU1004 is raised here.
The project dependencies have changed and that's all NU1004 is supposed to change.

Moreover, I'm not sure this actually tackles the problem in the linked issue, which is really about AssetTargetFallback not being applied through project refs when calculating.

@dotnet-policy-service
Copy link
Copy Markdown
Contributor

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 30 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@dotnet-policy-service dotnet-policy-service bot added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: NU1004: The project Xxx has no compatible target framework for .NET vs .NET Framework cross reference with -LockedMode

2 participants