Question
Is it possible to clear a specific NuGet package from NuGet local cache using command line?
Context
I would like to ensure when I am executing a package restore operation for a project, the very latest server binaries will be restored, not something from the cache. At the same time I do not want to delete all packages from the cache.
If you have NuGet.exe version 3.3 or higher you can clear the entire cache from the command line:
nuget locals <all | http-cache | packages-cache | global-packages> -clear
If your NuGet packages are downloaded to the NuGet v2 cache then you could just have a simple script to delete a particular .nupkg file from the packages cache.
del %LocalAppData%\NuGet\Cache\NUnit.2.6.4.nupkg
With the NuGet v3 cache the structure is a bit different so you would need to do remove a set of directories:
rmdir %UserProfile%\.nuget\packages\NUnit\2.6.4 /s
nuget
or dotnet
cli. There is a github issue to address that: https://github.com/NuGet/Home/issues/5713
rm -rf ~/.nuget/packages/<package-name>
<Project>
<Target Name="DeleteLocalCache" BeforeTargets="Pack">
<RemoveDir Directories="$(NugetPackageRoot)/$(PackageId.ToLower())/1.0.0-local"/>
</Target>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With