22 Nov
I sometimes need to remove all intermediate & resulting build files from a Visual Studio solution, either due to version conflicts or because of permissions issues. Powershell just made that job a whole lot easier.
Here’s the command to remove all obj & bin folders from a path (assuming you’re in the path now):
Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
If you’re not in the correct folder just replace .\ with the full or relative path. You’ll still need to close down Visual Studio first, the -Force switch will override permission failures, but not process locks.
Note: this does a forced delete without prompting for confirmation, so you’d better be really sure you want it all gone. I highly recommend tacking a -WhatIf after the last -Recurse to do a dry run first to see what will be deleted, i.e.:
Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse -WhatIf }
YMMV, but this has saved me much annoyance. If you know of any other handy scripts, drop them in a comment. Share the love!
4 Responses for "Use Powershell to delete all bin & obj folders"
Use Powershell to delete all bin …
You’ve been kicked (a good thing) – Trackback from DotNetKicks.com…
Use Powershell to delete all bin …
You’ve been kicked (a good thing) – Trackback from DotNetKicks.com…
PowerShell script to clean Visual Studio prior to Subversion check in…
PowerShell script to clean Visual Studio prior to Subversion check in…
PowerShell script to clean Visual Studio prior to Subversion check in…
PowerShell script to clean Visual Studio prior to Subversion check in…
Leave a reply