【问题标题】:How to connect Visual Studio to Team Foundation Server Team Project from C# code如何从 C# 代码将 Visual Studio 连接到 Team Foundation Server Team Project
【发布时间】:2013-02-04 02:21:31
【问题描述】:

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

【问题讨论】:

  • 您是否知道一旦将解决方案签入到 TFS 中,再次打开该解决方案将连接到 TFS?
  • 是的,我知道,但我想首先连接到 TFS 来探索资源,而不是打开特定的解决方案。
  • 仍然不确定您在寻找什么。源代码管理资源管理器不做你想做的事吗?
  • 可以,但问题是“如何将 Visual Studio 连接到 Team Foundation Server Team Project FROM C# CODE”,而不是使用资源管理器
  • 你真的应该用更多的要求来更新你的问题。显然,没有多少人有与您相同的要求。

标签: c# tfs


【解决方案1】:

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

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

Extending Team Explorer in 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);
                }
            }
        }
    }
}

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-02
      • 2014-05-16
      • 2017-06-17
      • 2019-12-25
      • 2011-02-23
      相关资源
      最近更新 更多