我想計算一個比較兩個文檔的unified diff。 (該差異是在一封電子郵件中去,和維基說統一差異是最好的純文本差異格式。)如何使用Team Foundation的庫來計算統一差異?
團隊基礎具有command line interface做
> tf diff /format:unified alice.txt bob.txt
- Alice started to her feet,
+ Bob started to her feet,
(在https://gist.github.com/hickford/5656513示例文件)
很棒,但我寧願使用一個庫,而不是啓動一個外部過程,通常的原因。
搜索MSDN,我發現Team Foundation有一個.NET庫Microsoft.TeamFoundation.VersionControl
。但是,文檔沒有給出任何計算差異的例子。
如何計算Team Foundation庫的統一差異?
編輯:我試過的方法 Difference.DiffItems
,但它沒有工作的diff.txt
留下的空文件。
var before = @"c:\alice.txt";
var after = @"c:\bob.txt";
var path = @"c:\diff.txt";
using (var w = new StreamWriter(path))
{
var options = new DiffOptions();
options.OutputType = DiffOutputType.Unified;
options.StreamWriter = w;
Difference.DiffFiles(
before, FileType.Detect(before, null),
after, FileType.Detect(after, null),
options);
}
Console.WriteLine(File.ReadAllText(path));
發現別人幾年前同樣的問題。 http://social.msdn.microsoft.com/Forums/en-US/tfsversioncontrol/thread/828ad9b0-def5-461c-bf9e-180d57f167a8 –