我正在尝试编写一个代码,给定 TFS 存储库中项目的路径和两个修订版,将计算这两个时刻的内容文件之间的差异。现在,代码可能如下所示:
using (var projectCollection = new TfsTeamProjectCollection(new Uri(repositoryUrl)))
{
projectCollection.EnsureAuthenticated();
var versionControlServer = (VersionControlServer)projectCollection.GetService(typeof(VersionControlServer));
string path = "$/MyProject/path/to/file.xml"
var before = new DiffItemVersionedFile(versionControlServer, path, VersionSpec.ParseSingleSpec(minRevision.ToString(), null));
var after = new DiffItemVersionedFile(versionControlServer, path, VersionSpec.ParseSingleSpec(maxRevision.ToString(), null));
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream))
{
var options = new DiffOptions();
options.Flags = DiffOptionFlags.EnablePreambleHandling;
options.OutputType = DiffOutputType.Unified;
options.TargetEncoding = Encoding.UTF8;
options.SourceEncoding = Encoding.UTF8;
options.StreamWriter = writer;
Difference.DiffFiles(versionControlServer, before, after, options, path, true);
writer.Flush();
var reader = new StreamReader(stream);
var diff = reader.ReadToEnd();
}
}
但是一旦执行此代码,diff
即使我确定该文件已在minRevision
和之间修改,该变量也是一个空字符串maxRevision
。
minRevision
如果文件在 中不存在或被删除,则此代码也会引发异常maxRevision
,但这似乎是以后要解决的问题,一旦我让这个东西处理仅编辑过的文件。
编辑
检查临时文件后,我确定文件的两个版本都已正确下载。计算差异或将差异写入流或将差异复制到字符串时出现问题。