How to get the nuget cache folder location programmatically

Viewed 9091

I need to get from a .NET app (that is not .NET Core app) the list of directories where NuGet stores its packages.

I know by default it is in C:\Users\[YourUsername]\.nuget\packages so an option is to iterate over all users assuming the current Windows user that runs the process owns the right to access other users data. Moreover if this default dir is changed by the user I am stuck.

An answer is provided here through

nuget locals packages-cache -list

but it is not .NET code and it seems to be an obsolete option according to the answer.


Moreover I'd like to understand the logic of .NET Core NuGet packages locations, because I can see some .NET Core packages in 3 locations:

  • C:\Program Files\dotnet\shared\Microsoft.NETCore.App (don't contain AspNetCore packages)
  • C:\Users\[UserName]\.nuget\packages (do contain AspNetCore packages)
  • C:\Program Files (x86)\Microsoft SDKs\NuGetPackages (do contain AspNetCore packages)
1 Answers
Related