2009-05-18 52 views
4

我正在尋找一個實用工具,它會根據解決方案文件的位置自動移除SourceSafe綁定。我發現了幾個提到這個工具:刪除SourceSafe綁定的實用程序?

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

那樣子正是我需要的 - 刪除.scc文件和修改的.sln和*凸出文件。但是,我無法弄清楚如何真正得到這個實用程序 - 這個帖子上的附件似乎實際上並不存在。

有沒有人有這個工具的副本或知道我可以找到類似的東西之前我自己重寫它?我有137種解決方案解除綁定,因此手動執行此操作不是一個有吸引力的選擇。

回答

7

我不是很久以前寫這種類型的效用和你在正確的軌道上完成需要做的事情。

這裏有一些代碼讓你開始。它應該爲所有.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(); 
    }); 

編輯PROJ文件

//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(); 
    }); 
+0

工作很好,謝謝!我確實必須先刪除所有文件的只讀屬性,儘管... – shampoopy 2009-05-18 17:57:31

1

如果只有你至極處理文件系統的影響,普通的命令提示符下的命令應該能夠做到這一點:

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

謝謝,但要完全刪除綁定,您需要從.sln和.csproj文件中刪除一些gunk以及...這就是我正在尋找的位。 – shampoopy 2009-05-18 15:58:57

1

添加以下代碼,在刪除它們之前將該文件設置爲非只讀:

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

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

0

我使用Cygwin,你: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 
0

我已經擴大了Mikael's VSSBindingRemover應用。下面是變化的完整列表:

  • 更新解決了Visual Studio 2010中
  • 更新項目到.NET 4.0。
  • 已更新的正則表達式在清理後刪除解決方案和項目文件中的空行。
  • 添加刪除.suo文件的代碼。
  • 修改代碼以刪除所有文件的只讀屬性。
  • 增加了對DTS(.dtproj),C++(.vcxproj)和Deployment(.vdproj)項目類型的支持。
  • 將核心功能分離到自己的庫中,可以在其他項目中輕鬆使用。
  • 將現有的windows客戶端分離到使用核心功能庫的自己的項目中。
  • 創建了一個使用核心功能庫的命令行客戶端。命令行客戶端通過命令行參數以及標準輸入流接受其輸入,因此它支持管道。