Из TFS мне нужен код для извлечения имени проекта из определенной коллекции, передавая имя коллекции в качестве параметра, используя MVC Asp.net - PullRequest
0 голосов
/ 06 июня 2018
    public ActionResult Connect()
    {
            List<string> Collected = new List<string>(10);
            Uri configurationServerUri = new Uri("xxxxxxtfsurl");
            TfsConfigurationServer configurationServer =

            TfsConfigurationServerFactory.GetConfigurationServer
            (configurationServerUri);

            ITeamProjectCollectionService tpcService = 
            configurationServer.GetService<ITeamProjectCollectionService>();

            foreach (TeamProjectCollection tpc in 
             tpcService.GetCollections())
             {
                 Collected.Add(tpc.Name);
             }
             ViewBag.List = Collected;



             return PartialView();

       }

Я получил коллекцию, используя контроллер в MVC, но может ли кто-нибудь помочь мне получить проекты из определенной коллекции

1 Ответ

0 голосов
/ 07 июня 2018

Если вы просто хотите получить командные проекты из определенной коллекции, вы можете использовать приведенный ниже пример кода:

Установить пакет Nuget Microsoft.TeamFoundationServer.ExtendedClient .

using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Client;

class Program
{
    static void Main(string[] args)
    {
        string collection = @"http://ictfs2015:8080/tfs/DefaultCollection";
        TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName(collection));
        tfs.EnsureAuthenticated();
        VersionControlServer vcs = tfs.GetService<VersionControlServer>();
        TeamProject[] teamProjects = vcs.GetAllTeamProjects(true);

        foreach (TeamProject proj in teamProjects)
        {
            System.Console.WriteLine(string.Format("Team Project: {0}", proj.Name));
        }
        System.Console.ReadLine();
    }
}

Если вы хотите получить все коллекции и их командные проекты, попробуйте следующий пример кода:

using System;
using System.Collections.ObjectModel;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Framework.Client;

namespace GetProjectList
{
    class Program
    {
        static void Main(String[] args)
        {
            // Connect to Team Foundation Server
            //     Server is the name of the server that is running the application tier for Team Foundation.
            //     Port is the port that Team Foundation uses. The default port is 8080.
            //     VDir is the virtual path to the Team Foundation application. The default path is tfs.
            Uri tfsUri = (args.Length < 1) ?
                new Uri("http://ictfs2015:8080/tfs") : new Uri(args[0]);

            TfsConfigurationServer configurationServer =
                TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);

            // Get the catalog of team project collections
            ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren(
                new[] { CatalogResourceTypes.ProjectCollection },
                false, CatalogQueryOptions.None);

            // List the team project collections
            foreach (CatalogNode collectionNode in collectionNodes)
            {
                // Use the InstanceId property to get the team project collection
                Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
                TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);

                // Print the name of the team project collection
                Console.WriteLine("Collection: " + teamProjectCollection.Name);

                // Get a catalog of team projects for the collection
                ReadOnlyCollection<CatalogNode> projectNodes = collectionNode.QueryChildren(
                    new[] { CatalogResourceTypes.TeamProject },
                    false, CatalogQueryOptions.None);

                // List the team projects in the collection
                foreach (CatalogNode projectNode in projectNodes)
                {
                    Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName);
                }
            }
            // Display the project list on cosole window
            Console.ReadLine();
        }
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...