NuGet / Home

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

[Bug]: The deleted packages.lock.json file still shows as before in the Solution Explorer window when “RestorePackagesWithLockFile” is not enabled #11635

Closed v-luzh closed 2 years ago

v-luzh commented 2 years ago

NuGet Product Used

Other/NA

Product Version

Release-5.11.x\5.11.1.17

Worked before?

No response

Impact

It bothers me. A fix would be nice

Repro Steps & Context

Details about Problem

VS Version: D16.11\32228.343 NuGet Version: Release-5.11.x\5.11.1.17 OS Version: Windows-11-Enterprise-21H2

Repro steps

  1. Create a project [e.g. Class Library (.NET Framework)] and generate a lock file “packages.lock.json” alongside the csproj file.
  2. Install a PackageReference package into the project (to generate some content into the lock file).
  3. Run restore and close the solution/VS.
  4. Delete the lock file (which you generated in step1) and run restore again.
  5. Check the lock file should not be regenerate.
  6. Reopen this solution and go to Solution Explorer window to see if the lock file is deleted (or looks like it is deleted as expected screenshot showing) in the window too.

Expected

The deleted packages.lock.json file should show as a deleted file or removed (that's what we do for .NET Core projects) in the Solution Explorer window. Below is what we show on 17.2 Preview 2 (Main\32228.143). image

Actual

The deleted packages.lock.json file still shows as before in the Solution Explorer window as below. image

Notes:

1.It is not a regression. We just think it should be fix on VS 16.11. 2.It doesn't repro on 17.2 Preview 2 (Main\32228.143).

Verbose Logs

No response

erdembayar commented 2 years ago

I didn't test with 16.11+5.11.1.17, but I did test with latest VS17.2 Int Preview and I can repro similar issue, but experience is bit different. Above-described issue repro for netcore project, but not for packages.config projects. After I delete packages.lock.json files from each project then restore again then same file regenerates for netcore but not for packages.config

image

Could you please retest this with VS17?

nkolev92 commented 2 years ago

@erdembayar I think the scenario is legacy package reference. So create a .NET Framework project, and when you install a package, select PackageReference.

erdembayar commented 2 years ago

@erdembayar I think the scenario is legacy package reference. So create a .NET Framework project, and when you install a package, select PackageReference.

PackageReference is package name?

nkolev92 commented 2 years ago

PackageReference is the project restore style.

.NET Core projects are PackageReference, but CPS based PackageReference, so different project system. Legacy PackageReference are old style projects, not SDK based, not CPS based, but the long project files that normally support packages.config by default.

v-luzh commented 2 years ago

Hi @erdembayar, It doesn't repro on 17.2 Preview 2 (Main\32228.143). The behavior on VS 17.2 is reasonable as the screenshot I uploaded in Expected section above.

erdembayar commented 2 years ago

I tried to repro with actual version (D16.11\32228.343 5.11.1.17) in description. I can see packages.lock.json in FileExplorer, but not in VS.

image

Am I missing something?

aortiz-msft commented 2 years ago

@v-luzh does this issue repo on the latest version of 16.11?

nkolev92 commented 2 years ago

Delete the lock file and run restore again.

Worth calling out how the file is being deleted.

In VS? Through File Explorer? The legacy project system doesn't support globbing, or automatic refreshing so it might be a red herring.

v-luzh commented 2 years ago

Hi @aortiz-msft Yes, it repro on the latest version of 16.11 (that's D16.11\32228.343 which we filed this bug on). Hi @nkolev92, we deleted the file on disc (in File Explorer) which you created manually in step 1. But 17.2 support automatic refreshing for the legacy project system as what I mentioned in Expected section above. Hi @erdembayar, we used C# Class Library (.NET Framework) project, not the C# Class Library (.NET Core).

erdembayar commented 2 years ago

Hi @aortiz-msft Yes, it repro on the latest version of 16.11 (that's D16.11\32228.343 which we filed this bug on). Hi @nkolev92, we deleted the file on disc (in File Explorer) which you created manually in step 1. But 17.2 support automatic refreshing for the legacy project system as what I mentioned in Expected section above. Hi @erdembayar, we used C# Class Library (.NET Framework) project, not the C# Class Library (.NET Core).

Yes, I'm using Library (.NET Framework) project. But still couldn't repro, could you create gif animation please? Maybe there is something I'm missing. image

nkolev92 commented 2 years ago

If this is only about the file, there's nothing NuGet can/should do about it, only project system.

I imagine the same thing could apply if the files was any random text file.

v-luzh commented 2 years ago

Hi @erdembayar , please refer to below gif animation. DeletedStillExist

erdembayar commented 2 years ago

2 things in question.

  1. Why did you create empty packages.lock.file manually?
  2. VS creates it for you when you open solution since it does implicit restore, right?
zivkan commented 2 years ago

@erdembayar https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#enabling-the-lock-file

Once a project has packages.lock.json file in its root directory, the lock file is always used with restore even if the property RestorePackagesWithLockFile is not set. So another way to opt-in to this feature is to create a dummy blank packages.lock.json file in the project's root directory.

If there is no lock file on disk, and the project has not set the MSBuild property RestorePackagesWithLockFile (this test scenario, from the title of this github issue) then no, VS/NuGet will not re-create the lock file.

v-luzh commented 2 years ago

Hi @erdembayar,

  1. That's one test case of Repeatable Restore Test. The purpose is to verify restoring will not regenerate the deleted lock file when “RestorePackagesWithLockFile” is not enabled.
  2. VS will not create it for you if you didn't set “RestorePackagesWithLockFile”.

This is not a regression since it reproes on 16.10.0 Preview 1.0 [31025.218.d16.10]. Why it is OK on VS 17.2 Preview3 latest? I guess that's because VS improved the experience on how to show deleted file in Solution Explorer window on VS 17.2 Preview3. But we think it should be fix on 16.11 since the behavior in VS 17.2 Preview3 is more reasonable than before.

nkolev92 commented 2 years ago

This sounds like something we should move to project team and let them decide how to handle it.

You can probably replace packages.lock.json with any non compile file and it's likely to repro. It doesn't seem like it has anything to do with lock files in particular.

v-luzh commented 2 years ago

Hi @nkolev92, I agree with you. Could you please help to confirm which area path should we move this bug to? I will move it later.

nkolev92 commented 2 years ago

The path should be DevDiv\NET Tools\Project

v-luzh commented 2 years ago

@nkolev92 Thanks. Created a VS bug 1499811 to track this issue. I'm closing this one.