Search code examples
c#visual-studio-2010winmerge

How to "programmatically" integrate diff tool with Visual Studio


Is there a way to "programatically" integrate a diff tool (like WinDiff and WinMerge) with Visual Studio 2010? These files are not the files found at Solution Explorer.

The program would have to search and store in the List the files found from certain directory, and then compare the files with same names recursively.


Solution

  • As far as I can gather, you're looking for the TFS Difference class. Here's an example of how to use it:

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