As you know, Visual Studio’s “Clean Solution” doesn’t always delete everything from your bin and obj folders. Wouldn’t it be awesome if you had a bulletproof way of deleting all your bin and obj folders in your solution just by typing “DeleteBinObj” in your Package Manager Console? Now you can! Here’s how:

In your Visual Studio solution folder, create a file called “DeleteBinObj.ps1” that includes this code:

##########################################################
# PLEASE READ:
# 
# This script will be loaded by Visual Studio only when
# the solution is loaded therefore any changes you make 
# to it will not be effective until after you exit Visual 
# Studio and reload the solution.
##########################################################
function global:DeleteBinObj()
{
	Get-ChildItem .\ -include bin,obj -recu -Force | remove-item -force -recurse
}

In Visual Studio, go to your Solution Items folder (or create one) and Add Existing Item, pointing to the DeleteBinObj.ps1 file you just created.

Now close and reopen Visual Studio and load your solution.

In the Package Manager Console, enter the command

DeleteBinObj

If you refresh your projects, you’ll see that the bin folders are gone and the obj folders are gutted (sometimes a couple TemporaryGeneratedFiles linger in the obj directory).

Enjoy!