5
votes

When looking up the location that the NuGet packages are stored we noticed that some of the dlls were stored at C:\Users\Username\.nuget\packages while others were stored at C:\Program Files\dotnet\sdk\NuGetFallbackFolder.

For example, the microsoft.aspnetcore.all package folder is present in both directories on my dev pc (C:\Users\Username\.nuget\packages contains 2.0.7 and 2.1.0, while C:\Program Files\dotnet\sdk\NuGetFallbackFolder contains 2.0.0, 2.0.3, 2.0.5, 2.0.6 and 2.0.8).

According to the book "C# 7 and .NET Core 2.0 High Performance" by Ovais Mehboob Ahmed Khan. The default path should be C:\Users\Username\.nuget\packages.

Why are the files separated into the different folders?

Note: We are referencing microsoft.aspnetcore.all version 2.0.8 in most of our projects. Most of the other packages we reference in our projects alternate between the two folders.

1
I believe the NuGetFallbackFolder is populated during SDK installation as a sort of "packages you're likely to need" step. (Possibly when you install new tools/templates as well, but I'm not sure.)Jon Skeet
From the .NET Core documentation - NuGetFallbackFolder contains a cache of NuGet packages used by an SDK during the dotnet restore step. The other folder is for NuGet packages used by a project that are not included with the .NET Core SDK and for projects that do not use the NuGetFallbackFolder, such as non .NET Core projects.Matt Ward

1 Answers

2
votes

.NET Core introduced the concept of Nuget caching (a bit similar to GAC). All packages downloaded only once to a specific folder and reused for all projects. It is needed because of .NET Core 2.x-3.x now composed from hundreds of packages. So the framework now is very granular you use what you need. This created a now type of issue the Nuget Hell (used to we had DLL Hell). To make developers life easier MS introduced "aggregating" packages e.g. microsoft.aspnetcore.all (which contains nothing just references everything but actually if you do self contained build it will include only what you are using not all DLLs).

As you mentioned now you can find installed Nuget packages under you User account e.g.: C:\Users\< your userName >.nuget\packages.

According to this documentation you can run this command which will list all Nuget folders on your machine:

dotnet nuget locals all -l

The result will be something like this (folder names self are explanatory):

C:\Users\...>dotnet nuget locals all -l
info : http-cache: C:\Users\...\AppData\Local\NuGet\v3-cache
info : global-packages: C:\Users\...\.nuget\packages\
info : temp: C:\Users\...\AppData\Local\Temp\NuGetScratch
info : plugins-cache: C:\Users\...\AppData\Local\NuGet\plugins-cache