如何以编程方式查找TFS 2010中变更集中各个文件的代码流失信息?

时间:2011-06-21 20:17:08

标签: c# .net tfs tfs2010 tfs-sdk

我需要能够以编程方式查找TFS 2010中变更集中各个文件的代码流失信息(添加,更改,删除行)。我需要执行此操作的程序是桌面客户端应用程序。

任何人都知道如何做到这一点?你有想分享的示例代码吗?

2 个答案:

答案 0 :(得分:8)

这是一个起点:

        TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://WhateverServerUrl");
        IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
        VersionControlServer VsServer = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
        IBuildDetail build = buildServer.GetAllBuildDetails(new Uri("http://WhateverBuildUrl"));

        List<IChangesetSummary> associatedChangesets = InformationNodeConverters.GetAssociatedChangesets(build);


        foreach (IChangesetSummary changeSetData in associatedChangesets)
        {
            Changeset changeSet = VsServer.GetChangeset(changeSetData.ChangesetId);
            foreach (Change change in changeSet.Changes)
            {
                bool a = change.Item.IsContentDestroyed;
                long b = change.Item.ContentLength;
            }
        } 

Changeset具有以下内容:

    public Change[] Changes { get; set; }
    public int ChangesetId { get; set; }
    public CheckinNote CheckinNote { get; set; }
    public string Comment { get; set; }
    public string Committer { get; set; }
    public DateTime CreationDate { get; set; }
    public string Owner { get; set; }

变更具有以下内容:

    public ChangeType ChangeType { get; }
    public Item Item { get; }
    public ReadOnlyCollection<MergeSource> MergeSources { get; }

项目具有以下内容:

    public Uri ArtifactUri { get; }
    public Uri ArtifactUriLatestItemVersion { get; }
    public int ChangesetId { get; }
    public DateTime CheckinDate { get; }
    public static IComparer Comparer { get; }
    public long ContentLength { get; }
    public int DeletionId { get; }
    public int Encoding { get; }
    public byte[] HashValue { get; }
    public bool IsBranch { get; }
    public bool IsContentDestroyed { get; }
    public int ItemId { get; }
    public Stream DownloadFile();
    public void DownloadFile(string localFileName);

答案 1 :(得分:0)

如果您愿意使用多维数据集,则可以使用它来获取代码覆盖率。 http://blogs.msdn.com/b/jampick/archive/2010/07/06/tfs-2010-code-churn-report-getting-additional-detail.aspx