Clearing all bin and obj folders using SlightlyPosher and PowerShell

 

Sometimes an msbuild.exe /t:Clear doesn’t remove everything and it can be a little slow on larger solutions. Within the SlightlyPosher environment you’ll find a Module called VS.psm1, and this contains a handy little script when you need to do some house keeping.

function Clear-Assemblies($directory)
{
    Get-ChildItem $directory -include bin,obj -Recurse | foreach ($_) { 
        "Cleaning: " + $_.fullname
        remove-item $_.fullname -Force -Recurse 
    }
}

 

It’s pretty simply and to the point, just navigate to the root directory of the solution you want to clear down, and run this command.

Clear-Assemblies

It will recursively remove all bin and obj folders, and let you know what it deleted.

image

Great for when you need to copy source code without the added bulk of these folders or just purge any old bits for a clean build.

blog comments powered by Disqus