views:

1208

answers:

5

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.

+1  A: 

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
Stijn Sanders
thanks, but to completely remove the bindings, you need to remove some gunk from the .sln and .csproj files as well... that's the bit i'm looking for really.
shampoopy
+6  A: 

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();
    });
Jeremy
Worked great, thanks! I did have to remove the read-only attribute on all the files first, though...
shampoopy
oops, forgot about that part
Jeremy
+1  A: 

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);

juanjo.arana
+1  A: 

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.

Mikael Koskinen
A: 

Provided solution is working great for csproj files but not for vdproj files. could not add this as comment as question is marked answered.

BigBoss