August 21, 2005
Omar Shahine's Clean Sources is a nifty little right-click app for .NET developers:
This application does one thing. It adds an explorer shell menu to folders that when selected will recursively delete the contents of the bin, obj and setup folders. If you have a .NET project that you wish to share with someone, this is useful to remove the unnecessary stuff from the folder before you zip it up and send it off.
There's one glaring omission here, though. The source control bindings aren't removed! And neither are the local user setting files. I finally had some time, so...
Presenting Clean Sources Plus. It adds a right-click menu to folders that does the following:
- Removes bin, obj, Debug and Release folders
- Removes source control bindings from project and solution files
- Removes user setting files
The result is a very clean, minimal set of .NET solution files, suitable for upload or sharing.
Updated to version 1.1 on 11/10/05 with the following new features:
- Added second context menu "Clean and Zip Sources" which also zips the entire folder contents into a single zip file. This zip file is placed in the root folder and shares the same name as the folder.
- The regex patterns used to determine what files and folders to delete are now set in the .config file. This way you can customize what gets deleted without recompiling.
I tested this with both C# and VB projects, but I'm not 100% sure it works for all other types of projects. It shouldn't break anything, but I may have missed some oddball project type (database? setup?) source bindings. And I only tested against the typical SourceSafe bindings. Anyway, test it out and let me know if there are any issues.*
You may also be interested in TreeTrim, which is based on this project.
* If this app deletes all your source code, then it's Omar's fault.
Posted by Jeff Atwood
is useful to remove the unnecessary stuff from the folder before you zip it up and send it off.
Now that I'm re-reading this, it seems logical that there should be an additional right click to do this as well.. why not cut out the middleman? eg
"Clean Sources and Zip"
"Clean Sources, Zip and Email"
But what's the best way to ZIP the files without adding a bunch of dependencies to our solution? We could use the zip assembly.. or is there an easy-ish way to programmatically drive the "compressed folders" support in XP?
This sounds handy, but I wish VS.NET would have let me simply organize my sources the way I want in the first place. I prefer having all source separate from bin and obj directories, so that it is easier to perform these sorts of clerical tasks.
Great utility! Thanks for enhancing Omar's already slick tool, Clean Sources. This works great!
Why not just skip the clean step and do "Zip Sources"? It can just omit all the files that would have been cleaned but doesn't touch your disk, except to write the new Zip file.
Gah, slapped that submit button a wee bit early. As I was about to say...
Should be relatively easy to edit the files in memory, zip them in memory, then save the zip somewhere for emailing. Not sure what the free options are for emailing without persisting the zip to disk, I've only ever used commercial email components. I probably should download the source and see how it's currently done, eh? :-)
Thanks again Jeff!
Very cool utility, Jeff.
One thing on the Zipping (which is a great idea)... there are still W2K users our here (yeah, yeah, I know), so please don't bind this utility to XP+, if possible.
David's got a great point... A "Safe Zip Sources" option, in addition to the others, that didn't touch original files would be pretty cool too.
The hard part would be the source control binding removal... Maybe backup/rename existing file, remove bindings and save as original file name, zip, copy old/original file over the cleaned version, delete backup.. etc, etc...
LOL, easy for me to say... Since I have the source maybe I should shut-up and just do it!!! ;)
Damn open source... LOL
One possible (and easy) improvement:
Can you also try to delete _svn folders? They are created by a special version of Subversion compatible with VS.NET web projects.
Thanks Jeff. Just what I was looking for.
I made a small change to store the Directory, File and Binding pattern in a .config file so it's easy to change when you find new directories. I use Vault which has an _sgbak folder to remove.
I updated the project to version 1.1 incorporating some of the features in the comments here. The details are in the post, but to summarize:
- "Clean and Zip Sources" menu item
- file and folder deletion regex patterns are set in .config file
I couldn't figure out a way to (easily) automatically spawn an email with an attachment. Using a mailto: URL with an attachment param definitely doesn't work..
I didn't implement the "safe" no-touch zip option yet. Maybe for version 1.2.
I'd also like the context menu to be a submenu, since we may have 3-4 options in it once the "safe" options are online. That's pushing it a bit for a right-click menu on every folder. But I couldn't figure out how to set up the registry to achieve that. Hints??
Thanks Jeff, v. useful.
I quickly knocked up a MAPI class, so you can now create the emails. You can find it here.
Great tool! I've done a similar tool that finds orphaned items, i.e. items that are on disk but not specified as part of a project. The link is on my blog. I can't post the url of my blog for some reason. Anyway, google for "steve dunn" blog. Cheers, Steve Dunn.
Hi Jeff, thanks for the useful utility. While trying to set the configuration file to be able to delete .svn directories, I've incurred into the problem that the Directory.Delete method fails if the directory contains readonly files, so I've slightly edited your code to first navigate all the directory subtree and remove all the readonly attributes from the files. Your DeletePath method becomes:
Private Sub DeletePath(ByVal path As String)
If IsDirectory(path) Then
SetAllFilesReadWrite(path) ' added this call
If GetFileReadOnly(path) Then
Catch ex As Exception
DumpException(ex, "delete file or path", path)
And the body of the SetAllFilesReadWrite method is as following:
Private Sub SetAllFilesReadWrite(ByVal path As String)
Dim di As New DirectoryInfo(path)
For Each file As FileInfo In di.GetFiles()
If GetFileReadOnly(file.FullName) Then
For Each dir As DirectoryInfo In di.GetDirectories()
Could you update it for VS2008?
It's turning the SLN files into "unknown VS version" on the VS version selector, and upon opening the cleaned solutions, a SCC message mentioning "Visual Studio 6.0" appears :S
Do you happen to have an update to .NET 2.0 or 3.5 by any chance? Possibly with a nice visual configuration dialog? :-)
Here is another request for a VS2008 update.
How about a custom MSBuild task that will do this? I'm thinking about giving it a try.
Another request for vs2008 update.
Would also love to see an update to 2008, and the "no touch" version which creates the nice zip file with touching the original source.
So, will there be a 2008 version?
I've created a tool that will allow you to right-click on a project or solution in Windows Explorer and zip it up. It can also attach the zip file to an email using the users email client.
If you are interested, the project is called VS Project Zipper (source code is available). You can get more information about it from...
are you still maintaining this?
I've been working on a tool that extends CleanSourcesPlus. It's called TreeTrim and has most of the features discussed here (working copy or 'no touch').
Please feel free to take a look and spread the word at http://code.google.com/p/treetrim/
Is there a tool to clean up unused methods/functions from the .net solution??
Please let me know ASAP
Thanks in advance
Meera, resharper cleans unused methods.
Perfect! You read my mind with the app.config regex setup. Good show!
I get the same Visual Studio 6.0 message as Daniel. Any ideas as to why?
Also, I've removed the source binding files from the config but it still unbinds me from TFS.
By the way, great tool, really useful, so thanks! :) I use it to take code home...get from TFS, zip, take home, back to work, rebind, "tfpt uu" + "tfpt online". Easy! (tfpt = Team Foundation Power Tools)
Download link seems to be down?
Confirmed, both download links are broken. Is there any way you can repost them?
Thank you very much in advance!