我不久前写了这种类型的实用程序,你在正确的轨道上需要做些什么。
这里有一些代码可以帮助您入门。它应该适用于所有 .Net 项目(VS 2003 - VS 2008),包括部署项目:
//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));
删除 VSS 文件
//Delete all vss files
VssFiles.ForEach(vss =>{vss.Delete();});
编辑 sln 文件
//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();
});
编辑项目文件
//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();
});