2013-10-30 20 views
3

有沒有一種「編程式」將差異工具(如WinDiff和WinMerge)與Visual Studio 2010集成的方法?這些文件不是解決方案資源管理器中找到的文件。如何「以編程方式」將差異工具與Visual Studio集成

該程序將不得不搜索並在列表中存儲從某個目錄找到的文件,然後遞歸地比較具有相同名稱的文件。

+0

究竟是什麼試圖實現?你只是想確定文件,或文件中的文本不同,或者你是否真的想讓WinMerge出現在每個文件中? –

回答

4

據我所知,你正在尋找的TFS Difference類。這裏有一個如何使用它的例子:

string f1 = @"file1.cs"; 
string f2 = @"f2.cs"; 

Microsoft.TeamFoundation.VersionControl.Common.DiffOptions options = new Microsoft.TeamFoundation.VersionControl.Common.DiffOptions(); 
options.Recursive = true; 
options.StreamWriter = new System.IO.StreamWriter(Console.OpenStandardOutput()); 
options.UseThirdPartyTool = true; 
options.OutputType = Microsoft.TeamFoundation.VersionControl.Common.DiffOutputType.Unified;    

var diff = Difference.DiffFiles(
      f1, FileType.Detect(f1, null), 
      f2, FileType.Detect(f2, null), 
      options); 

while (diff != null) 
{ 
    // Do whatever it is that you want to do here    
    diff = diff.Next; 
} 
0
+0

謝謝。但有沒有辦法自動比較winmerge或windiff中的文件並使用C#語言? – NullReferenceException

+1

如果您即將在您的代碼中啓用windiff,可以通過啓動一個新進程來調用它,查看[ProcessStartInfo](http://msdn.microsoft.com/zh-cn/library/system.diagnostics.processstartinfo (v = vs.110)的.aspx)。 – slepox

+0

我想在沒有實際執行WinDiff的情況下比較文件。我還沒有找到解決方案......也許對我來說最好的方法就是使用ReadAllText方法編寫代碼。 – NullReferenceException

相關問題