0

是否可以从代码将 Visual Studio 连接到 TFS 团队项目?我找到了如何连接到 TFS 的文章:http: //msdn.microsoft.com/en-us/library/vstudio/bb286958.aspx但是这允许我从代码对 TFS 执行基本操作,但不连接 Visual Studio。 样本

4

2 回答 2

1

据我了解你的问题,你不能......你有3个选择:

1-为 VS Team Explore 做一个扩展,这个扩展将取决于你已经使用 VS 连接。

在 Visual Studio 2012 中扩展团队资源管理器

2- 制作一个单独的 exe,以便您使用TeamProjectPicker,以便您可以选择要连接的 TFS 和团队项目。

    using System.Windows.Forms;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.Server;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Application.EnableVisualStyles(); // Makes it look nicer from a console app.
                //"using" pattern is recommended as the picker needs to be disposed of
                using (TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.MultiProject, false))
                {
                    DialogResult result = tpp.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        System.Console.WriteLine("Selected Team Project Collection Uri: " + tpp.SelectedTeamProjectCollection.Uri);
                        System.Console.WriteLine("Selected Projects:");
                        foreach (ProjectInfo projectInfo in tpp.SelectedProjects)
                        {
                            System.Console.WriteLine(projectInfo.Name);
                        }
                    }
                }
            }
        }
    }

3- 使用 API for TFS 和硬编码路径或将其放入配置文件中,如下所示:

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

namespace TfsApplication
{
    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://Server:Port/VDir") : 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);
                }
            }
        }
    }
}
于 2013-01-31T19:39:12.530 回答
0

在这里您可以找到将 Visual Studio 连接到 TFS 的分步指南

http://tfs.visualstudio.com/en-us/learn/code/connect-vs/

于 2013-02-03T18:21:31.110 回答