fsprojects / Paket

A dependency manager for .NET with support for NuGet packages and Git repositories.
https://fsprojects.github.io/Paket/
MIT License
2.02k stars 525 forks source link

Clearing cache corrupts paket tool #3879

Open vdurante opened 4 years ago

vdurante commented 4 years ago

Description

Running dotnet paket clear-cache command causes paket to become corrupt and unusable

Repro steps

  1. Install paket locally in an application using dotnet core dotnet new tool-manifest, dotnet tool install paket, dotnet tool restore
  2. Run dotnet paket clear-cache:
    C:\repos\MyApp> dotnet paket clear-cache
    Paket version 5.247.4
    - C:\Users\vitor\.nuget\packages
    Performance:
    - Runtime: 1 second
    Paket failed with
    -> UnauthorizedAccessException: Access to the path 'C:\Users\vitor\.nuget\packages\paket\5.247.4\tools\netcoreapp2.1\any\Argu.dll' is denied.
  3. Paket carshes and becomes corrupt:
    C:\repos\MyApp>dotnet paket --version
    A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\vitor\.nuget\packages\paket\5.247.4\tools\netcoreapp2.1\any\'.
    Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\Users\vitor\.nuget\packages\paket\5.247.4\tools\netcoreapp2.1\any\paket.runtimeconfig.json file specifying the appropriate framework.
ChrSteinert commented 4 years ago

Hmm. This is unfortunate. Paket, when installed on a per-project basis, deletes itself. When it is installed as a global tool (dotnet tool install -g paket) it does not deletes itself.

Unfortunately it cannot remove the files loaded by the executing paket itself (like Argu.exe), but some other files get removed and then for the next execution some files are missing.

You explicity delete the nuget cache. Thus it is expected that the nuget package Paket does not work anymore. What would be your expected behaviour?

vdurante commented 4 years ago

@ChrSteinert I didn't know local tools where kept in global cache. I didn't expect installed tools to be kept in cache at all. Later I installed it globally to test it and it worked as expected. I was just trying to find a workaround for this #3116

Maybe to prevent it getting corrupt, local installations of Paket should uninstall or reinstall Paket at the end to prevent it becoming corrupt, or find some workaround, or at least show a message to explain why that is happening. Either way, that is no big deal.

Thank you!

ChrSteinert commented 4 years ago

I'd say the clear-cache should

Opinions, @forki ?

vdurante commented 4 years ago

@ChrSteinert I don't know how clear-cache works internally on Paket, but nuget has several options for clearing cache (all | http-cache | global-packages | temp). Maybe Paket installed locally should not clean tooling cache or something.

ChrSteinert commented 4 years ago

The issue is, that there is no dedicated tooling cache. (Non-global) Tools reside within the "normal" packages folder. This is where it gets so tricky. Alas, I'll have a look at what NuGet actually does there.

vdurante commented 4 years ago

True, idk why I thought tools were installed somewhere else.

I am gonna guess NuGet (dotnet nuget) has no issue since it is bundled within dotnet instead of being distributed as a tool. Maybe there is no solution to that unless Paket implements its own cache-clearing from scratch.

ChrSteinert commented 4 years ago

The current cache-clear just tries to delete every file in the common nuget cache folders recursively. I can use some better erorr handling though ;) (And a warning cannot hurt as well)