List all files checked into TFS by a user in past

2020-06-12 03:45发布

We have many projects with several files inside each. Files can be checked in from the main solution root, from the project level and from the individual level.

Is there a way to find all files checked in by a particular user during the past few days, for all the levels?

标签: tfs
2条回答
太酷不给撩
2楼-- · 2020-06-12 04:08

If you have the TFS power tools installed you can use the command "tfpt searchcs" from a visual studio command prompt. This will allow you to search for all change sets checked in by a particular user and also set a start and end date along side some other filters. This might meet your needs

查看更多
小情绪 Triste *
3楼-- · 2020-06-12 04:11

I think it's not possible to drill down to the files of each changeset of a user within a given timeframe by using the standard reporting facilities of TFS.

The following uses the TFS-SDK & should accomplish the task:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace GetCheckedInFiles
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://tfsURI"));

            var versionControl = teamProjectCollection.GetService<VersionControlServer>();

            //enforcing 3 days as "past few days":
            var deltaInDays = new TimeSpan(3, 0, 0, 0);
            DateTime date = DateTime.Now - deltaInDays;

            VersionSpec versionFrom = GetDateVSpec(date);
            VersionSpec versionTo = GetDateVSpec(DateTime.Now);

            IEnumerable results = versionControl.QueryHistory("$/", VersionSpec.Latest, 0, RecursionType.Full, "User" , versionFrom, versionTo, int.MaxValue, true, true);
            List<Changeset> changesets = results.Cast<Changeset>().ToList();

            if (0 < changesets.Count)
            {
                foreach (Changeset changeset in changesets)
                {
                    Change[] changes = changeset.Changes;
                    Console.WriteLine("Files contained in "+changeset.ChangesetId+" at "+changeset.CreationDate+" with comment "+changeset.Comment);

                    foreach (Change change in changes)
                    {
                        string serverItem = change.Item.ServerItem;
                        Console.WriteLine(serverItem + "   "+change.ChangeType);
                    }
                    Console.WriteLine();
                }
            }

        }

        private static VersionSpec GetDateVSpec(DateTime date)
        {
            string dateSpec = string.Format("D{0:yyy}-{0:MM}-{0:dd}T{0:HH}:{0:mm}", date);
            return VersionSpec.ParseSingleSpec(dateSpec, "");
        }
    }
}

The GetDateVSpec was copied from this post by Robaticus

查看更多
登录 后发表回答