我想计算比较两个文档的统一差异.(差异是进入电子邮件,维基百科说统一差异是最好的纯文本差异格式.)
团队基础有一个命令行界面,这样做
> tf diff /format:unified alice.txt bob.txt
- Alice started to her feet,
+ Bob started to her feet,
Run Code Online (Sandbox Code Playgroud)
(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 ); …Run Code Online (Sandbox Code Playgroud)