C#TFS SDK从变更集获取项目

时间:2018-12-05 12:01:22

标签: c# tfs tfs-sdk

我想从特定变更集中的项目中获取内容。使用我的代码,我可以得到正确数量的项目,但是该项目的每个属性都是空的,只有正确的URL被填写。所有其他属性均设置为null。 我该怎么解决?

string collectionUri = @"https://tfs.myServer.de/MyProject";
using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri)))
{
   TfvcHttpClient tfvcClient = tpc.GetClient<TfvcHttpClient>();
   var changedItems = tfvcClient.GetChangesetAsync(125453).Result;
   IEnumerable<TfvcChange> changesetChanges=tfvcClient.GetChangesetChangesAsync(changedItems.ChangesetId).Result;
   foreach (var itemsChange in changesetChanges)
   {
      Console.WriteLine(itemsChange.NewContent.Content);
   }
}

1 个答案:

答案 0 :(得分:0)

这将为您提供变更集项目的内容

private static async Task ReadContent(TfvcHttpClient tfvcClient)
{
    var changesetId = 123456;
    var changesetChanges = await tfvcClient.GetChangesetChangesAsync(changesetId);
    var tfvcVersionDescriptor = new TfvcVersionDescriptor(null, TfvcVersionType.Changeset, changesetId.ToString());

    foreach (var changesetChange in changesetChanges)
    {
        var path = changesetChange.Item.Path;
        Stream contentStream = await tfvcClient.GetItemContentAsync(path, versionDescriptor: tfvcVersionDescriptor);
        using (StreamReader streamReader = new StreamReader(contentStream))
        {
            var content = streamReader.ReadToEnd();
        }
    }
}