Question

I'm looking for a utility that will remove SourceSafe bindings automatically given the location of the solution file. I found several mentions of this tool:

http://codebetter.com/blogs/darrell.norton/archive/2008/05/16/sourcesafe-binding-remover.aspx

That looks like exactly what I need - deletes .scc files and modifies .sln and .*proj files. However, I can't figure out how to actually get the utility - the attachment on that post seems to not actually be there.

Does anyone have a copy of this tool or know where I can find something similar before I rewrite it myself? I have 137 solutions to de-bind so doing this manually is not an attractive option.

Was it helpful?

Solution

I wrote this type of utility not too long ago and you are on the right track with what needs to be done.

Here's some code to get you started. It should work for all .Net projects (VS 2003 - VS 2008) including deployment projects:

//get list of all files to be edited/removed
            SlnFiles = new List<FileInfo>(SelectedDir.GetFiles("*.sln", SearchOption.AllDirectories));
            ProjFiles = new List<FileInfo>(SelectedDir.GetFiles("*.*proj", SearchOption.AllDirectories));
            VssFiles = new List<FileInfo>(SelectedDir.GetFiles("*.vssscc", SearchOption.AllDirectories));
            VssFiles.AddRange(SelectedDir.GetFiles("*.vsscc", SearchOption.AllDirectories));
            VssFiles.AddRange(SelectedDir.GetFiles("*.scc", SearchOption.AllDirectories));
            VssFiles.AddRange(SelectedDir.GetFiles("*.vspscc", SearchOption.AllDirectories));

Deleting VSS files

//Delete all vss files
            VssFiles.ForEach(vss =>{vss.Delete();});

Editing sln files

//Edit sln files 
    SlnFiles.ForEach(sln =>
    {
    string fullName = sln.FullName;
    string relPath = sln.Directory.FullName.Replace(workingDir.FullName, string.Empty);

    StreamReader reader = sln.OpenText();
    String text = reader.ReadToEnd();
    reader.Close();
    string regex = "\tGlobalSection\\(SourceCodeControl\\) [\\s\\S]*? EndGlobalSection\r\n";
    RegexOptions options = ((RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline) | RegexOptions.IgnoreCase);
    Regex reg = new Regex(regex, options);

    text = reg.Replace(text, string.Empty);
        if (text.StartsWith(Environment.NewLine))
            text = text.Remove(0, 2);
        StreamWriter writer = new StreamWriter(fullName);
        writer.Write(text);
        writer.Flush();
        writer.Close();
    });

Editing proj files

//edit proj files
    ProjFiles.ForEach(proj =>
    {
    string fullName = proj.FullName;
    string relPath = proj.Directory.FullName.Replace(workingDir.FullName, string.Empty);

    StreamReader reader = proj.OpenText();
    String text = reader.ReadToEnd();
    reader.Close();

    string regex = "\"*<*Scc.*?(>|\\W=\\W\").*?(>|\")";
    RegexOptions options = ((RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline) | RegexOptions.IgnoreCase);
    Regex reg = new Regex(regex, options);

    text = reg.Replace(text, string.Empty);
    StreamWriter writer = new StreamWriter(fullName);
    writer.Write(text);
    writer.Flush();
    writer.Close();
    });

OTHER TIPS

Here's the link to a newly created VSSBindingRemover. The software has been created based on Jeremy's and juanjo.arana's answers. You can download the source code and the executable from the GitHub.

If it's only the impact on the file-system you wich to handle, plain command prompt commands should be able to do it:

del *.scc /s /q
attrib -r *.* /s

add the following code to set the file as not read-only before you delete them:

var allFiles = slnFiles.Union(projFiles).Union(vssFiles).ToList();

allFiles.ForEach(f => f.IsReadOnly = true);

I use Cygwin, do you :P

find.exe . -type f -name *.dsp -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*Scc_ProjName.*$//g'
find.exe . -type f -name *.dsp -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*Scc_LocalPath.*$//g'
find.exe . -type f -name *.dsw -print0 | xargs -0 -r sed -i '/begin.source.code.control/,/end.source.code.control/d'
find.exe . -type f -name *.sln -print0 | xargs -0 -r sed -i '/GlobalSection(SourceCodeControl)/,/EndGlobalSection/d'
find.exe . -type f -name *.*proj -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*SccProjectName.*$//g'
find.exe . -type f -name *.*proj -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*SccLocalPath.*$//g'
find.exe . -type f -name *.*proj -print0 | xargs -0 -r perl -p -i.vssbak -e 's/^.*SccProvider.*$//g'
find.exe . -type f -name *.vssbak -print0 | xargs -0 -r rm -f 
find.exe . -type f -name *.*scc -print0 | xargs -0 -r rm -f 

I've expanded Mikael's VSSBindingRemover application. Here is the complete list of changes:

  • Updated solution to Visual Studio 2010.
  • Updated project to .NET 4.0.
  • Updated regular expressions to remove blank lines in solution and project files after the cleanup.
  • Added code for removing .suo files.
  • Modified code to remove read-only property on all files.
  • Added support for DTS (.dtproj), C++ (.vcxproj) and Deployment (.vdproj) project types.
  • Separated core functionality into its own library that can be easily used within other projects.
  • Separated existing windows client into its own project that uses core functionality library.
  • Created a command line client that uses core functionality library. The command line client accepts its input through both the command line parameters, as well as standard input stream, so it supports piping.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top