1

有没有办法列出项目中所有已更改的文件,但按每个文件的更改次数排序?

我想进行代码审查,但只能从最活跃的文件中选择。

4

2 回答 2

0

您可以尝试使用 Excel 作为 TFS 报告工具,如此博客文章中所示:

http://www.woodwardweb.com/vsts/getting_started.html

附言。我在这个问题中找到了那个链接。

于 2012-07-25T09:12:41.510 回答
0

我搜索了不同的方法,最后我发现最好的方法是使用 TFS API
这里是代码:

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

namespace VControl
{
    class Program
    {
        class SourceElement
        {
            public string filename;
            public int numberOfModification;

        }
        static void Main(string[] args)
        {
             TfsTeamProjectCollection projectCollection = new 
            TfsTeamProjectCollection(new Uri("http://server:8080/tfs/ProjectCollection/"),
                new System.Net.NetworkCredential("username", "password"));
              projectCollection.EnsureAuthenticated();
            Workspace workspace = null;
            Boolean createdWorkspace = false;
            String newFolder = String.Empty;
             VersionControlServer versionControl = projectCollection.GetService<VersionControlServer>();
             var teamProjects = new List<TeamProject>(versionControl.GetAllTeamProjects(false));
             String workspaceName = String.Format("{0}-{1}", Environment.MachineName, "TestWorkspace");
            try
            {
                workspace = versionControl.GetWorkspace(workspaceName, versionControl.AuthorizedUser);
            }
            catch (WorkspaceNotFoundException)
            {
                workspace = versionControl.CreateWorkspace(workspaceName, versionControl.AuthorizedUser);
                createdWorkspace = true;
            }
            var serverFolder = String.Format("$/{0}", teamProjects[0].Name) + "/solutionFolder/";
            var localFolder = Path.Combine(Path.GetTempPath(), "localFolder") + "/solutionFolder/";
            var workingFolder = new WorkingFolder(serverFolder, localFolder);
            // Create a workspace mapping.
            workspace.CreateMapping(workingFolder);
            if (!workspace.HasReadPermission)
            {
                throw new SecurityException(
                    String.Format("{0} does not have read permission for {1}",
                    versionControl.AuthorizedUser, serverFolder));
            }

            // Get the files from the repository.
            workspace.Get();
            string[] directories = Directory.GetDirectories(workspace.Folders[0].LocalItem);
            FileStream outputFile = new FileStream("result.txt", FileMode.Create);
            StreamWriter  writer = new StreamWriter(outputFile);     
            List<SourceElement> fileLiset = new List<SourceElement>();
            foreach (string dir in directories)
            {
                foreach (string file in Directory.GetFiles(dir))
                {
                    string filenamae = System.IO.Path.GetFileName(file);
                    Item source = versionControl.GetItem(file);
                    System.Collections.IEnumerable history = versionControl.QueryHistory(file,
                    VersionSpec.Latest, 0, RecursionType.Full, null, null, null, 300, true, true, false, false);
                    int numberOfModification = 0;
                    foreach (var item in history)
                        numberOfModification++;
                    SourceElement fileElement = new SourceElement();
                    fileElement.filename = filenamae;
                    fileElement.numberOfModification = numberOfModification;
                     fileLiset.Add(fileElement);
                }
                }
         var sortedList = fileLiset.OrderBy(x=> x.numberOfModification);
                    // Loop through keys.
            foreach (var key in sortedList)
            {
                writer.WriteLine("{0}: {1}", key.filename, key.numberOfModification);
            }
            writer.Close();
        }
    }
 }
于 2016-07-20T07:45:37.917 回答