Friday, February 24, 2017

NuGet package doesn't get unpacked when added to visual studio

The Problem

After creating a package and then making alterations to it many times during the learning process of making a package from a dll I came across the issue where I'd tried and install a package from the feed and it would either not find the dependencies or now the odd behavior of installing without unpacking and adding a reference to my project.

The Explanation

Turns out there are four caches associated with NuGets.

They are as follows from https://docs.microsoft.com/en-us/nuget/consume-packages/managing-the-nuget-cache :

http-cache: C:\Users\user\AppData\Local\NuGet\v3-cache   #3.x cache
packages-cache: C:\Users\user\AppData\Local\NuGet\Cache  #2.x cache
global-packages: C:\Users\user\.nuget\packages\          #Global cache
temp: C:\Users\user\AppData\Local\Temp\NuGetScratch      #Temp folder

You have to clear them to get the packages to not take from the dead cache versions and use the new fresh versions you've altered or created new ones of.

The Solution

To clear them you can run any of the following commands for each one or all the caches.

nuget locals http-cache -clear        #Clear the 3.x cache
    nuget locals packages-cache -clear    #Clear the 2.x cache
    nuget locals global-packages -clear   #Clear the global cache
    nuget locals temp -clear              #Clear the temporary cache
    nuget locals all -clear               #Clears all caches
Edit:

Additional resources:
https://connect.microsoft.com/VisualStudio/feedback/details/1656768/installing-certain-nuget-packages-fails-to-actually-extract-the-dll-files-to-the-relevant-lib-folder-and-fails-to-add-an-assembly-reference-to-the-csproj-file