如何使用团队基础的库来计算标准差异? [英] How to use Team Foundation's library to calculate unified diff?
问题描述
我要计算一个统一差异比较两个文件。 (该差异是走在一封电子邮件,和维基百科说,统一的差异是最好的纯文本差异格式。)
团队基础具有命令行界面一>做
> TF差异/格式:统一alice.txt bob.txt
- 爱丽丝开始她的脚,
+鲍勃开始了她的脚,
(示例文件在 https://gist.github.com/hickford/5656513 )
辉煌,但我宁愿使用的库比启动外部过程中,通常的原因。
在搜索MSDN,我发现球队基金会有一个.NET库<一href="http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client(v=vs.80).aspx"相对=nofollow> Microsoft.TeamFoundation.VersionControl
。但是,文件并未给出计算差异的任何实例。
我如何计算出一个统一的差异与团队基础库?
编辑:我试过的方法
<一href="http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.difference.aspx"相对=nofollow> Difference.DiffItems
,但没有奏效,文件 diff.txt
是空的。
VAR @C:\ alice.txt;
后= @C:\ bob.txt变种;
VAR路径= @C:\ diff.txt;
使用(VAR W =新的StreamWriter(路径))
{
VAR的选择=新DiffOptions();
options.OutputType = DiffOutputType.Unified;
options.StreamWriter = W;
Difference.DiffFiles(
之前,FileType.Detect(前,空)
之后,FileType.Detect(后为空),
选项);
}
Console.WriteLine(File.ReadAllText(路径));
猜猜这是不可能的:(只能从与 tf.exe
在命令行中执行此操作。
I want to calculate a unified diff comparing two documents. (The diff is to go in an email, and Wikipedia says unified diff is the best plain text diff format.)
Team Foundation has a command line interface do that
> tf diff /format:unified alice.txt bob.txt
- Alice started to her feet,
+ Bob started to her feet,
(Example files at https://gist.github.com/hickford/5656513)
Brilliant, but I'd rather use a library than start an external process, for the usual reasons.
Searching MSDN, I found Team Foundation has a .NET library Microsoft.TeamFoundation.VersionControl
. However, the documentation didn't give any examples of calculating a diff.
How do I calculate a unified diff with the Team Foundation library?
Edit: I tried the method
Difference.DiffItems
but it didn't work—the file diff.txt
was left empty.
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));
Guess it's not possible :( You can only do this from the command line with tf.exe
.
这篇关于如何使用团队基础的库来计算标准差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!