VSClean Command Line Tool

By on 5/18/2009

I don’t know about you, but I have a lot of code on my computer.  As anyone who follows me on Twitter knows, I’m often running out of space on my laptop.  So yesterday, I was running WinDirStat on my harddrive to see what I could clean up.  I found that I had a significant amount of space spent on the contents of my /bin/* folders.  As any developer would know, this is where Visual Studio places binary files when it compiles.  So any time I have a visual studio solution from some old project, inevitably, I’ll have tons and tons dlls and exes just sitting around, not to mention content that may be part of the solution such as .mdb files, and in the more extreme cases, XNA game content.

So I started opening the folders and deleting them when I lamented that I wished I could just tell visual studio to run a Clean Solution command on all these files.  Then it hit me, visual studio uses MSBuild to do it’s compiling.  So why not write a simple tool that recurses through my dev directory and runs the msbuild clean command on all the solutions it finds.  Brilliant!

To that end, I’d like to introduce the command line tool VSClean. Download here: http://codecube.net/bloguploads/VSClean.zip

Update: This project has been moved to CodePlex: http://vsclean.codeplex.com/

The zip file above is the source code.  Once you compile it, just run it from the command line and pass in your root source code directory as the first parameter:
> VSClean “c:\dev”
Once you run this, it’ll iterate through all the folders in that directory looking for .sln files.  Once it finds them, it runs this command:
C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe “c:\dev\theSolution.sln” /m /t:clean
Of course, if you’ve installed the framework in a different path, you’ll have to change the const variable at the top of the class.  Once this is done, you can feel good that all of your old source code isn’t taking up unnecessary space :-)

See more in the archives