Skip to content

restore locked mode and force evaluate should error - #4434

Closed
martinrrm wants to merge 3 commits into
devfrom
dev-martinrrm-lockedmode-and-forceevaluate-error
Closed

martinrrm wants to merge 3 commits into
devfrom
dev-martinrrm-lockedmode-and-forceevaluate-error

Conversation

@martinrrm

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#8222

Regression? Last working version:

Description

Using RestoreLockedMode and RestoreForceEvaluate at the same time is contradictory.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

@martinrrm
martinrrm requested a review from a team as a code owner February 2, 2022 22:24
@martinrrm

Copy link
Copy Markdown
Contributor Author

I'm not 100% sure if NU1004 is the correct code I should use here.

@nkolev92 nkolev92 left a comment

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.

We could use a test here.

Also given that we're introducing a new customer facing message or potentially a new log code, we'll probably need an issue for that.

{
success = false;

// invalid input since LockedMode and RestoreForce should not be used together.

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.

RestoreForce and RestoreForceEvaluate are actually different.


// directly log to the request logger when we're not going to rewrite the assets file otherwise this log will
// be skipped for netcore projects.
await _request.Log.LogAsync(RestoreLogMessage.CreateError(NuGetLogCode.NU1004, message));

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.

If you look at the log code, it refers to dependency changes, but this is more of an input thing, but this is closer to https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1005.

I think we either reuse NU1005 or add a new one.
What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hmm I think we can reuse NU1005 because is related to RestorePackagesWithLockFile but the error is more related to the use of commands so we can go either way.

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.

It's conflicting/bad input.

NU1005 was gonna be my suggestion as well.

We can document the 2 instances where that warning is raised.

@martinrrm

Copy link
Copy Markdown
Contributor Author

@nkolev92 I'll add the tests for this, but looking at the code, is this error only going to happen when the lockfile exists?

@nkolev92

nkolev92 commented Feb 2, 2022

Copy link
Copy Markdown
Member

@martinrrm

Either way is fine, as I don't expect customers who aren't using lock files would run this.

Might be easier to just raise the error every time the input is weird like that.

@ghost ghost 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 Feb 10, 2022
@ghost

ghost commented Feb 10, 2022

Copy link
Copy Markdown

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 7 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.

2 similar comments
@ghost

ghost commented Feb 17, 2022

Copy link
Copy Markdown

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 7 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.

@ghost

ghost commented Feb 24, 2022

Copy link
Copy Markdown

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 7 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.

@ghost ghost closed this Mar 3, 2022
@martinrrm martinrrm reopened this Mar 3, 2022
@ghost ghost removed 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 3, 2022
@martinrrm

Copy link
Copy Markdown
Contributor Author

Documentation update pr NuGet/docs.microsoft.com-nuget#2685

nkolev92
nkolev92 previously approved these changes Mar 3, 2022
erdembayar
erdembayar previously approved these changes Mar 4, 2022
@zivkan

zivkan commented Mar 9, 2022

Copy link
Copy Markdown
Member

question: Say I have <RestoreLockedMode>true in my repo Directory.Build.props. I then run dotnet restore --force-evaluate. Am I going to get the error?

If so, what is the expected workflow for a customer who has the Directory.Build.props setting, and they edit a csproj and need to update the lock files?

@martinrrm
martinrrm force-pushed the dev-martinrrm-lockedmode-and-forceevaluate-error branch from e8fcebc to 98de990 Compare March 9, 2022 23:42
@martinrrm

Copy link
Copy Markdown
Contributor Author

@zivkan Not sure, I havent worked with Directory.Build.props before, I'll take a look into that case, you think that case can block this pr to be merged?

@zivkan

zivkan commented Mar 10, 2022

Copy link
Copy Markdown
Member

@martinrrm think of it from a customer's point of view.

They edit their csproj to add a new PackageReference, or change a package version. They run restore, and get an error saying that the project is inconsistent with the lock file, and to run force evaluate. They then run force evaluate, but get an error saying that you can't run force evaluate and locked mode at the same time. Is the "average developer" going to understand/find a way to become successful?

I'm not sure if the messages output to console, or the docs (that you recently updated in NuGet/docs.microsoft.com-nuget#2685), give enough information to customers on how to resolve the issue. While the docs does say "Rerun restore without locked mode to regenerate the lock file.", if the customer didn't provide --locked-mode on the command line, how are they going to be successful in upgrading the package in their project? Locked mode might be set in an environment variable, it might be in a Directory.Build.props, it might be in any other props or targets file that is imported by the project.

MSBuild's complexity makes it impossible for us to generate a great error message. Whether or not it should block this PR, I sugggest you play around a little to lean more about MSBuild, and then talk to the PMs and get an agreement with them about what the customer experience should be.

@nkolev92
nkolev92 dismissed stale reviews from erdembayar and themself via 98de990 March 11, 2022 21:14
@ghost ghost 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, 2022
@ghost

ghost commented Mar 18, 2022

Copy link
Copy Markdown

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 7 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.

@martinrrm
martinrrm force-pushed the dev-martinrrm-lockedmode-and-forceevaluate-error branch from 98de990 to fa7df2d Compare March 23, 2022 18:43
@ghost ghost removed 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 23, 2022
@jeffkl jeffkl added Merge next release PRs that should not be merged until the dev branch targets the next release and removed Merge next release PRs that should not be merged until the dev branch targets the next release labels Mar 29, 2022
@ghost ghost 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 Apr 12, 2022
@ghost

ghost commented Apr 12, 2022

Copy link
Copy Markdown

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 7 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.

@martinrrm
martinrrm force-pushed the dev-martinrrm-lockedmode-and-forceevaluate-error branch from fa7df2d to 15f3ed9 Compare April 14, 2022 22:27
@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Apr 14, 2022
@martinrrm
martinrrm force-pushed the dev-martinrrm-lockedmode-and-forceevaluate-error branch from c3b2d4b to f4cc362 Compare April 14, 2022 23:27
@jeffkl

jeffkl commented Apr 19, 2022

Copy link
Copy Markdown
Contributor

Team Review: We think ForeReevaluate should just override restore locked mode or the error message should tell the user to specify /Property:RestoreLockedMode=false which would override whatever they've defined in their project or common import.

@martinrrm

Copy link
Copy Markdown
Contributor Author

PM Office Hours: ForceEvaluate will override restore locked mode, and if we use RestoreLockedMode we show a message warn the user that ForceEvaluate is overriding.

@ghost ghost 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 Apr 27, 2022
@ghost

ghost commented Apr 27, 2022

Copy link
Copy Markdown

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 7 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.

@martinrrm
martinrrm marked this pull request as draft May 3, 2022 16:46
@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label May 3, 2022
@ghost ghost 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 Aug 9, 2022
@ghost

ghost commented Aug 9, 2022

Copy link
Copy Markdown

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 7 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.

@ghost ghost closed this Aug 16, 2022
@nkolev92
nkolev92 deleted the dev-martinrrm-lockedmode-and-forceevaluate-error branch July 2, 2024 20:45
martinrrm added a commit that referenced this pull request Jun 4, 2026
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 added a commit that referenced this pull request Jun 4, 2026
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 added a commit that referenced this pull request Jun 5, 2026
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 uses a dedicated new code, NU1512, 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. A dedicated code (rather than reusing the existing
NU1005 error) lets this warning carry its own documentation.

Fixes: NuGet/Home#8222

Co-authored-by: Copilot <[email protected]>
martinrrm added a commit that referenced this pull request Jun 9, 2026
#7451)

* Warn when RestoreForceEvaluate overrides RestoreLockedMode

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]>

* Use a dedicated NU1512 warning code instead of reusing NU1005

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]>

---------

Co-authored-by: Copilot <[email protected]>
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

RestoreLockedMode=true & RestoreForceEvaluate=true should error

5 participants