Clean Sources Plus

Omar Shahine's Clean Sources is a nifty little right-click app for .NET developers:


This is a companion discussion topic for the original blog entry at: http://www.codinghorror.com/blog/2005/08/clean-sources-plus.html

LOL!

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”
“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.

Very nice! Removing source bindings by hand is pain, I’ve had to do it on a few occasions. Thanks!

SharpZipLib supports in memory compression, its in the FAQ. It’s a very handy feature. http://wiki.sharpdevelop.net/default.aspx/SharpZipLib.FrequentlyAskedQuestions

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? :slight_smile:

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!!! :wink:

Damn open source… LOL

Nice, thanks.

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.
Tomas

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.

Works great!

Richard

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.

a href="http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71PostID=1"http://www.vbusers.com/codecsharp/codeget.asp?ThreadID=71PostID=1/a

thanks
andrew

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)
Try
If IsDirectory(path) Then
SetAllFilesReadWrite(path) ’ added this call
Directory.Delete(path, True)
Else
If GetFileReadOnly(path) Then
SetFileReadOnly(path, False)
End If
File.Delete(path)
End If
Catch ex As Exception
DumpException(ex, “delete file or path”, path)
End Try
End Sub

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
SetFileReadOnly(file.FullName, False)
End If
Next
For Each dir As DirectoryInfo In di.GetDirectories()
SetAllFilesReadWrite(dir.FullName)
Next
End Sub

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

Thanks!

Do you happen to have an update to .NET 2.0 or 3.5 by any chance? Possibly with a nice visual configuration dialog? :slight_smile:

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.