Tag Archive: Powershell


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!

UPDATE:  I’ve created a solution script so you can run this with a single command

 

If you want to quickly delete all the bin and obj folders in a solution:

  1. Make sure you have Microsoft’s Productivity Power Tools 2012 installed in your Visual Studio’s Extensions and Updates.
  2. Right-click on the solution in Solution Explorer
  3. Open Command Prompt
  4. Run powershell
  5. Paste and run this:  Get-ChildItem -include bin,obj -recu -Force | remove-item -force -recurse

Replace cmd with Console2

Scott Hanselman has a great post on how to set up a better cmd, powershell, and vscommand all-in-one console with separate tabs.  The upgraded console lets you copy & paste like a normal person, let’s you set default directories, and even resizes in both directions! Here’s my setup in retro green-on-black. (Notice the cmd, Powershell, and VSCommand icons in the tabs)

image

Here’s how you do it:

View full article »

© 2017 Robert Corvus