다음을 통해 공유


콘솔 응용 프로그램에서 Team Foundation Server에 연결

프로그래밍 방식으로 실행 되는 서버에 연결할 수 있습니다 Team Foundation 하 고 다음 예제를 사용 하는 경우 해당 서버의 팀 프로젝트에 액세스 합니다.이 예제를 수정 하는 경우 서비스를 사용할 수 있습니다는 Getting Additional Team Foundation Services 이 항목의 뒷부분에서 설명 합니다.사용자를 대신 하 여 다른 사용자로 가장을 사용 하 여 작동할 수도 Acting on Behalf of Another User (Impersonation) 이 항목의 뒷부분에서 설명 합니다.

항목 내용

예제

다음 예제를 사용 하는 경우 포함 된 팀 프로젝트와 팀 프로젝트 컬렉션을 나열할 수 있습니다.

이 예제를 사용 하려면

  1. C# 콘솔 응용 프로그램을 만듭니다.

  2. 다음 어셈블리에 대한 참조를 추가합니다.

    [!참고]

    Microsoft.TeamFoundation.Client 및 microsoft.teamfoundation.common에 표시 되지 않는 경우는 .NET 탭의 참조 대화 상자를 사용은 찾아보기 어셈블리를 추가 하려면 탭.%ProgramFiles%\Microsoft Visual Studio 10.0\common7\ide\referenceassemblies\v2.0에서 찾을 수 있습니다.

  3. 이 항목의 뒷부분에 있는 코드의 Program.cs 내용을 대체 합니다.

  4. 해당 코드를 대체 서버, 포트, 및 VDir URL 서버로 참조 될 수 있도록 TfsConfigurationServer 개체를 생성 하는 데 사용 되는 url에서입니다.

    팁

    올바른 URL을 사용 하 고 있는지 확인 하려면 사용 팀 탐색기 서버에서 팀 프로젝트를 열고 서버 URL 속성을 확인 합니다.

    Team Foundation Server 속성: URL

    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);
                    }
                }
            }
        }
    }
    
    Imports System
    Imports System.Collections.ObjectModel
    Imports Microsoft.TeamFoundation.Client
    Imports Microsoft.TeamFoundation.Framework.Common
    Imports Microsoft.TeamFoundation.Framework.Client
    
    Module Module1
    
        Sub Main(ByVal sArgs() As String)
    
            ' Connect to the Team Foundation Server
            ' Server is the name of the server running the application tier for Team Foundation Server
            ' Port is the port that the Team Foundation Server uses. The default port is 8080.
            ' VDir is the virtual path to the Team Foundation application. The default value is tfs.
            Dim tfsUri As Uri
            If sArgs.Length = 0 Then
                tfsUri = New Uri("https://Server:8080/tfs")
            Else
                tfsUri = New Uri(sArgs(1))
            End If
    
            Dim configurationServer As New TfsConfigurationServer(tfsUri)
            configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri)
    
            ' Get the catalog of team project collections
            Dim collectionNodes As ReadOnlyCollection(Of CatalogNode)
            Dim gVar As Guid() = New Guid() {CatalogResourceTypes.ProjectCollection}
            collectionNodes = configurationServer.CatalogNode.QueryChildren(gVar, False, CatalogQueryOptions.None)
    
            ' List the team project collections
            For Each collectionNode In collectionNodes
                Dim collectionId As Guid = New Guid(collectionNode.Resource.Properties("InstanceID"))
    
                Dim teamProjectCollection As New TfsTeamProjectCollection(tfsUri)
                teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId)
                System.Console.WriteLine("Collection:" + teamProjectCollection.Name)
    
                ' Get a catalog of team projects for the collection
                Dim hVar As Guid() = New Guid() {CatalogResourceTypes.TeamProject}
    
                Dim projectNodes As ReadOnlyCollection(Of CatalogNode)
                projectNodes = collectionNode.QueryChildren(hVar, False, CatalogQueryOptions.None)
    
                ' List the team projects in the collection
                For Each projectNode In projectNodes
                    System.Console.WriteLine(" Team Project: " + projectNode.Resource.DisplayName)
                Next
    
            Next
    
    
        End Sub
    
    End Module
    
    

Team Foundation Services 추가 하기

GetService 메서드를 사용 하 여 추가 서비스에 액세스할 수 있는 추상 클래스 TfsConnection 정의 고 TfsConfigurationServerTfsTeamProjectCollection 구현.

사용 하는 경우는 TfsConfigurationServer 클래스 서비스는 전체 서버에 대 한 액세스.사용 하는 경우는 TfsTeamProjectCollection 클래스에 서비스 팀 프로젝트 컬렉션에 대 한 액세스.예를 들어,는 ITeamFoundationRegistry 서비스에 대 한 TfsConfigurationServer 등록 된 서버의 속성을 제공 합니다.동일한 서비스에서 취득 TfsTeamProjectCollection 등록 된 팀 프로젝트 컬렉션의 속성을 제공 합니다.일부 서비스는 팀 프로젝트 컬렉션에만 적용 됩니다.

서비스

TfsConfigurationServer

(서버 수준)

TfsTeamProjectCollection

(컬렉션 수준)

ITeamFoundationRegistry

확인 표시

확인 표시

IIdentityManagementService

확인 표시

확인 표시

ITeamFoundationJobService

확인 표시

확인 표시

IPropertyService

확인 표시

확인 표시

IEventService

확인 표시

확인 표시

ISecurityService

확인 표시

확인 표시

ILocationService

확인 표시

확인 표시

TswaClientHyperlinkService

확인 표시

확인 표시

ITeamProjectCollectionService

확인 표시

IAdministrationService

확인 표시

확인 표시

ICatalogService

확인 표시

VersionControlServer

확인 표시

WorkItemStore

확인 표시

IBuildServer

확인 표시

ITestManagementService

확인 표시

ILinking

확인 표시

ICommonStructureService3

확인 표시

IServerStatusService

확인 표시

IProcessTemplates

확인 표시

다른 사용자를 대신 하 여 (가장) 역할을 하

연결을 Team Foundation Server, 가장 id 이외의 응용 프로그램을 실행 하는 대신 역할을 지 원하는 메서드를 사용할 수 있습니다.연결 가장 된 id를 대신 하 여 수행 됩니다 수행 되는 작업에 따라.응용 프로그램 수 있지만 사용자의 id에서 실행할 연결 합니다 예를 들어, Team Foundation Server 는 사용자 B를 가장사용자는 이러한 상황에서 소스 코드를 변경에서 하면 변경 집합 체크 변경에는 사용자 B를 기록 합니다.

Bb286958.collapse_all(ko-kr,VS.110).gif팀 기반 Id를 사용 하 여

사용할 수 있는 IdentityDescriptor 개체에 연결할 때 Team Foundation Server id를 가장 하도록 지정 합니다.IdentityDescriptor Id 지정은 Team Foundation 정의 합니다.이 전략을 사용 하면 암호를 지정할 필요가 없습니다.인증 된 id가 있어야 합니다의 다른 사용자를 대신 하 여 요청을 권한 인증된 (사용자 A) 및 (사용자 B)의 가장 된 id가 같은 경우를 제외 하 고.

서버 수준

  • TfsConfigurationServer.TfsConfigurationServer(RegisteredConfigurationServer, IdentityDescriptor)

  • TfsConfigurationServer.TfsConfigurationServer(Uri, IdentityDescriptor)

컬렉션 수준

  • TfsTeamProjectCollection.TfsTeamProjectCollection(RegisteredProjectCollection, IdentityDescriptor)

  • TfsTeamProjectCollection.TfsTeamProjectCollection(Uri, IdentityDescriptor)

Bb286958.collapse_all(ko-kr,VS.110).gif인증 된 자격 증명을 사용 하 여

사용할 수 있는 ICredentials 개체에 연결할 때 Team Foundation Server id를 가장 하도록 지정 합니다.이 전략 특별 한 권한이 필요 하지 않은 있지만 만들 id의 암호를 얻을 수 있어야의 ICredentials 개체입니다.

구현을 지정할 수도 있습니다 ICredentialsProvider 연결을 Team Foundation Server 새 자격 증명에 대 한 요청을 처리 합니다.시스템의 구현을 호출 ICredentialsProvider 요청을 새로 지정 하는 경우 자격 증명에 지정 된 자격 증명의 ICredentials 개체가 제대로 인증 하거나 작업을 수행할 수 있는 권한이.

사용 하 여 사용자 자격 증명을 묻는 메시지를 표시는 UICredentialsProvider 클래스는 implements ICredentialsProvider 새 자격 증명을 묻는 로그온 대화 상자를 표시 합니다.

서버 수준

컬렉션 수준

Bb286958.collapse_all(ko-kr,VS.110).gif기술 조합 하 여

둘 다 수는 Team Foundation id 및 인증된 자격 증명을 연결할 때 Team Foundation Server.예를 들어, 응용 프로그램 사용자에 대 한 자격 증명으로 실행 하지만 사용자 B에 대 한 자격 증명을 사용 하 고 지정할 수는 IdentityDescriptor 사용자가 연결할 때 c Team Foundation Server.이 경우 해당 연결을 사용 하 여 만들어진 요청 사용자 B를 인증 하지만 사용자 C. 대신 수행 합니다.이 전략을 성공적으로 사용자 B가 있어야는 다른 사용자를 대신 하 여 요청을 사용 권한.

서버 수준

  • TfsConfigurationServer.TfsConfigurationServer(RegisteredConfigurationServer, ICredentials, ICredentialsProvider, IdentityDescriptor)

  • TfsConfigurationServer.TfsConfigurationServer(Uri, ICredentials, ICredentialsProvider, IdentityDescriptor)

컬렉션 수준

  • TfsTeamProjectCollection.TfsTeamProjectCollection(RegisteredProjectCollection, ICredentials, ICredentialsProvider, IdentityDescriptor)

  • TfsTeamProjectCollection.TfsTeamProjectCollection(Uri, ICredentials, ICredentialsProvider, IdentityDescriptor)

추가 리소스

팀 프로젝트 컬렉션을 사용하여 서버 구성

Team Foundation Server의 팀 프로젝트에 연결

TfsConnection, TfsConfigurationServer, 및 TfsTeamProjectCollection 클래스 소개 Microsoft 웹 사이트에서

가장 TFS 버전 제어 Api를 사용 하 여 Microsoft 웹 사이트에서.