Welcome to MSDN Blogs Sign in | Join | Help

How to: Diff files using TFS APIs?

You can use the Difference.DiffFiles method which compares two files using the internal diff engine, and return the linked list of DiffSegments:

DiffSegment ds = Difference.DiffFiles(fileA, FileType.Detect(fileA, null), fileB, FileType.Detect(fileB, null), new DiffOptions());

Console.WriteLine(ds.Next == null ? "Identical" : "Different");

// If you don’t have the files locally on disk, you’ll need to download them first:
// The path can be a temp file:
// Path.Combine(Environment.GetEnvironmentVariable("tmp"), "diff_" + someRandomValue);

string fileA = "Local path for file A";
string fileB = "Local path for file B";
VersionControlServer vcs = new TeamFoundationServer("http://tfs:8080").GetService(typeof(VersionControlServer));

vcs.DownloadFile("$/Proj/a", fileA);
vcs.DownloadFile("$/Proj/b", fileB);

Published Sunday, March 08, 2009 1:51 AM by mohamedg

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

No Comments

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker