PSFOM April - local nuget cache deleting function

April 09, 2017

I’ve been writing a few nuget packages lately, to try and promote best practices in build and deployment code.

Nuget caches packages in multiple places on your local machine, this can lead to a lot of confusion if a stale package is used instead of a proper one built by the CI server.

I’ve found myself deleting my nuget caches regularly and have written a simple function which i’ve found useful:

function nuke-get(){
    $caches = nuget locals all -list
    foreach ($cache in $caches){
        $cacheSplit = $cache.Split(":")
        $cacheName = $cacheSplit[0]
        $cachePath = $cache.Replace("$cacheName`: ", "")
        Write-Host "Deleting cache '$cacheName' at '$cachePath'"
        if(Test-Path $cachePath){
            Remove-Item -path "$cachePath\*" -Recurse
        } else {
            Write-Host "Nothing at path"
        Write-Host "Done"

This function requires for the nuget executable to be on your PATH. To use this function it’s easiest to add it to a powershell profile.

Profile picture

Website and blog of Chester Burbidge