简体   繁体   中英

Retrieving “Lightweight Code Comments” using Team Foundation Server API

from my ASP.Net App I want to retrieve all code comments for a specific changeset using the C# TFS Client SDK (or the REST API, if possible) of our on-prem TFS 2015 Update 3. I've already installed the nuget package Microsoft.TeamFoundationServer.ExtendedClient. I know how to get a changeset or a specific file - but I don't know how to load the comments.

轻量级代码注释

After getting the comments, I also like to change (add) comments to a changeset (not to a file).

Thx, for your help!

This can be achieved by using Microsoft.TeamFoundation.Discussion.Client in TFS Client SDK. Following is the code sample:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Discussion.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace LightweightCodeView
{
    class Program
    {
        static void Main(string[] args)
        {
            string projecturi = "https://xxx:8080/tfs/";
            int changesetid = xxx;
            TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri(projecturi));
            VersionControlServer vcs = ttpc.GetService<VersionControlServer>();
            Changeset cset = vcs.GetChangeset(changesetid);
            TeamFoundationDiscussionService tfds = new TeamFoundationDiscussionService();
            tfds.Initialize(ttpc);
            IDiscussionManager idm = tfds.CreateDiscussionManager();
            IAsyncResult iar = idm.BeginQueryByVersion(cset.ArtifactUri, QueryStoreOptions.ServerOnly, new AsyncCallback(Callback), null);
            var threads = idm.EndQueryByVersion(iar);
            foreach (DiscussionThread dt in threads)
            {
                Console.WriteLine(dt.RootComment.Content);
                Console.WriteLine(dt.RootComment.Author.DisplayName);
                Console.ReadLine();
            }
        //Update Changeset comments
        cset.Comment = "New Comments";
        cset.Update();
        }
        static void Callback(IAsyncResult result)
        {
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM