Repository navigation
NU1512 error when RestoreLockedMode=true and RestoreForceEvaluate=true - #7451
Merged
Merged
Conversation
martinrrm
commented
Jun 3, 2026
zivkan
previously approved these changes
Jun 4, 2026
kartheekp-ms
previously approved these changes
Jun 4, 2026
martinrrm
force-pushed
the
dev-mruizmares-fix8222LockedModeForceEvaluate
branch
from
June 4, 2026 22:41
9701332 to
057ef51
Compare
When restore ran with both RestoreLockedMode=true and RestoreForceEvaluate=true, the contradictory inputs were silently reconciled in favor of force-evaluate: the lock file was re-evaluated and regenerated, locked-mode enforcement never ran, and nothing told the user their locked-mode guarantee was being ignored. Per the PM/team decision recorded on the earlier attempt (#4434), force-evaluate should continue to take precedence so that the legitimate "edit a csproj, then force-evaluate to refresh the lock file" workflow keeps working (locked mode is often set in a Directory.Build.props). Instead of failing the restore, emit a warning so the override is no longer silent. The warning reuses NU1005 and is gated behind SdkAnalysisLevel >= 11.0.100, since the feature guide treats a new restore warning as an in-scope change that must be gated to avoid breaking -warnaserror builds on older SDKs. It is additionally guarded to fire only when a lock file is in play and on the original restore action, matching the surrounding locked-mode code paths. Fixes: NuGet/Home#8222 Co-authored-by: Copilot <[email protected]>
martinrrm
force-pushed
the
dev-mruizmares-fix8222LockedModeForceEvaluate
branch
from
June 4, 2026 22:59
057ef51 to
ca71b8e
Compare
zivkan
reviewed
Jun 4, 2026
nkolev92
reviewed
Jun 5, 2026
nkolev92
left a comment
Member
There was a problem hiding this comment.
Code looks fine. We need a different code.
martinrrm
force-pushed
the
dev-mruizmares-fix8222LockedModeForceEvaluate
branch
from
June 5, 2026 19:38
ca71b8e to
466d6d4
Compare
Per PR review feedback, give the "RestoreForceEvaluate overrides RestoreLockedMode" warning its own code rather than overloading the existing NU1005 error (which has the distinct meaning "Invalid combination of RestorePackagesWithLockFile and packages.lock.json file"). NU1512 sits in the restore input-warning range (1500-1599) and lets this warning carry its own documentation page. Co-authored-by: Copilot <[email protected]>
martinrrm
force-pushed
the
dev-mruizmares-fix8222LockedModeForceEvaluate
branch
from
June 5, 2026 19:41
466d6d4 to
60f1d30
Compare
nkolev92
approved these changes
Jun 5, 2026
kartheekp-ms
approved these changes
Jun 5, 2026
This was referenced Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Fixes: NuGet/Home#8222
Description
When restore runs with both
RestoreLockedMode=trueandRestoreForceEvaluate=true, the two contradictory properties were silently reconciled in favor ofRestoreForceEvaluate: the lock file was re-evaluated and regenerated, locked-mode enforcement never ran, and nothing told the user their locked-mode guarantee was being ignored.Root cause is in
EvaluatePackagesLockFileAsync(RestoreCommand.cs): the lock-file read and locked-mode enforcement are both nested behindif (!_request.RestoreForceEvaluate ...), so force-evaluate short-circuits locked mode entirely.This was previously investigated in #4434 (never merged). That PR proposed a hard error, but the recorded PM/team decision (Apr 2022) was the opposite:
RestoreForceEvaluateshould continue to overrideRestoreLockedMode, and a warning should inform the user that the override is happening — failing the build would block the legitimate "edit a csproj, then force-evaluate to refresh the lock file" workflow, especially whenRestoreLockedModeis set in aDirectory.Build.props.This PR implements that decision: restore still succeeds and force-evaluate still wins, but it now emits a warning (reusing NU1005) so the ignored locked mode is no longer silent:
The warning is gated by
SdkAnalysisLevel(minimum11.0.100), per the repo's feature guide which lists "new restore warning" as an in-scope change that must be gated to avoid breaking-warnaserrorbuilds on older SDKs. It is additionally guarded to fire only when a lock file is in play (_isLockFileEnabled) and on the original restore action (IsRestoreOriginalAction), matching the surrounding locked-mode code paths.The message is intentionally a single concise sentence, consistent with NuGet's existing warning/error style; the detailed explanation and remediation steps belong on the NU1005 documentation page.
Changes
EvaluatePackagesLockFileAsync, reusingNuGetLogCode.NU1005; restore behavior is otherwise unchanged (force-evaluate wins).Warning_RestoreLockedModeAndForceEvaluatestring (resx + Designer + regenerated xlf).RestoreLockedMode/RestoreForceEvaluateare marked do-not-localize.SdkAnalysisLevelis below the minimum.PR Checklist