I wrote this type of utility not so long ago, and you are on the right track with what needs to be done.
Here is the 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));
Delete VSS Files
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(); });
source share