NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

Fail to install another package with command “dotnet add package” after setting restore lock mode on Linux #12315

Open v-luzh opened 1 year ago

v-luzh commented 1 year ago

NuGet Product Used

dotnet.exe

Product Version

.NET SDK 7.0.100

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

Repro Steps:

1.Patch .NET SDK 7.0.100 with NuGet Client release-6.4.x\6.4.0.123 following the steps from: Patch dotnet SDK  (Web view)  

  1. Create multiple C# Console Application(.NET Core) projects using command on the patch SDK folder:
  2. Install a few ‘PackageReference’ packages into the projects.
  3. Set MSBuild property “RestorePackagesWithLockFile” to true in csproj file.
    <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
  4. Do a restore.
  5. Check it should have generated ‘packages.lock.json’ file alongside *.csproj file.
  6. Set msbuild property “RestoreLockedMode” to “true”.
    <RestoreLockedMode>true</RestoreLockedMode>
  7. Install another package with command “dotnet add package”.

    Expected: 

    Package installed successfully without errors.

    Actual: 

    Another package is failed to install with the error NU1004 showing as below. image

    Notes:  

  8. It reproes after patching .NET SDK 6.0.403 with NuGet Client release-6.3.x\6.3.2.1 on Linux.
  9. It reproes after patching .NET SDK 6.0.306 with NuGet Client release-6.2.x\6.2.3.1 on Linux.
  10. It reproes after patching .NET SDK 6.0.111 with NuGet Client release-6.0.x\6.0.4.6 on Linux.
  11. It reproes after patching .NET SDK 3.1.425 with NuGet Client release-5.7.x\5.7.4.4 on Linux & Windows.
  12. It reproes before patching above .NET SDKs on Linux too.
  13. It is not a regression since it reproes on .NET SDK 5.0.202 on Linux.
nkolev92 commented 1 year ago

@v-luzh

In notes, 4, you say that it reproes on Windows as well. I am guessing, it reproes on Windows with all versions?

We only care about the latest version, so no need to try with the older versions.

ghost commented 1 year ago

This issue has been automatically marked as stale because we have not received a response in 14 days. It will be closed if no further activity occurs within another 14 days of this comment.

v-luzh commented 1 year ago

Hi, @nkolev92 we didn't try the adding package step for other dotnet version on Windows last time, just performed it on 3.1.425. Today we executed the same steps on .NET SDK 7.0.101. It also reproes on Windows as below. image

kartheekp-ms commented 1 year ago

May be the solution here is to follow the suggestion in the docs i.e., pass an explicit --force-evaluate option to run restore to update the lock file. when RestoreLockedMode is true.

nkolev92 commented 1 year ago

There shouldn't be a need to run force evaluate. That's really meant for floating versions and hand editing.

dotnet add package should effectively "unlock" the same way the PM UI does that.

CiciLi1 commented 2 months ago

It still reproes on Dotnet SDK 9.0.100-rc.2.24420.21 patched with NuGet Client Dev\6.12.0.82.