Delete Obj/Bin folders in a Visual Studio solution

Delete Obj/Bin folders in a Visual Studio solution

Background

Most non-trivial applications have a lot of files of source code. Unless the application uses an interpreted language, those files are compiled into other types like executables and DLLs. Add in multiple configurations, and you will soon have many megabytes of files on your disks.

C# and web applications, in particular, usually have many files, binaries and DLLs in Obj and Bin folders. VS Solutions can also have many projects within them; some projects have hundreds, and others may have thousands of projects. Each project has an Obj and Bin folder of its own. Each project is compiled into those folders. If you have Release and Debug build configurations, each project will have two sets of Obj and Bin folders.

Over time, solution folders will grow to consume vast amounts of disk space.

Our flagship product at work has over 40GB of files. Over time, as you try different build configurations, the amount of space increases, too.

Recovering space

So, how do you recover space back?

You can clean a solution, but that doesn’t clear everything. It leaves a lot of unnecessary files, so that doesn’t work – I find it ridiculous after so many years that VS still doesn’t clear up properly.

Fortunately, there is a solution in the form of a little bit of Powershell: –

Get-ChildItem  c:\TFS  -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse  -WhatIf }

This recursively deletes all bin and obj folders from the start point (‘c:\TFS’ in this example).

Stephen

Hi, my name is Stephen Finchett. I have been a software engineer for over 30 years and worked on complex, business critical, multi-user systems for all of my career. For the last 15 years, I have been concentrating on web based solutions using the Microsoft Stack including ASP.Net, C#, TypeScript, SQL Server and running everything at scale within Kubernetes.