コンソール アプリケーションからの 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. URL が、サーバーを示すように TfsConfigurationServer のオブジェクトの製造に使用される URL のそのコード、置換 [サーバー]、[ポート]と VDir。

    ヒントヒント

    正しい 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 サービスを取得できます。

抽象型クラス TfsConnection を定義します TfsConfigurationServerTfsTeamProjectCollection を実行し、GetService 方法の 1 種類の追加サービスを使用してアクセスできます。

TfsConfigurationServer クラスを使用すると、すべてのサーバーのサービスのアクセスを制御します。TfsTeamProjectCollection クラスを使用すると、プロジェクト チーム コレクションのサービスのアクセスを制御します。たとえば、TfsConfigurationServerITeamFoundationRegistry サービスがサーバーの登録されたプロパティを提供します。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 に代わってその接続に基づいて行われます。たとえば、A のアプリケーションは、ユーザーの ID で移動ユーザーの 12 Z 対象に扮する Team Foundation Server への接続を作成ができました。ユーザーの 12 Z 対象、変更をチェックインしたユーザーを A のチェックインがこのような状況でソース・コードへの変更、変更を記録します。

Bb286958.collapse_all(ja-jp,VS.110).gifTeam Foundation ID を使用する

ID を指定するに Team Foundation Server に扮する接続すると IdentityDescriptor のオブジェクトを使用できます。IdentityDescriptor は Team Foundation が定義した ID を指定します。この工程を使用する場合、パスワードを指定する必要はありません。認証された ID がおよび以外と認証する *** 別のユーザーに代わって要求を行います。*** のアクセス許可が必要です (ユーザー A) と扮するユーザー (B) の ID は同じです。

サーバー レベル

  • TfsConfigurationServer.TfsConfigurationServer(RegisteredConfigurationServer, IdentityDescriptor)

  • TfsConfigurationServer.TfsConfigurationServer(Uri, IdentityDescriptor)

コレクション レベル

  • TfsTeamProjectCollection.TfsTeamProjectCollection(RegisteredProjectCollection, IdentityDescriptor)

  • TfsTeamProjectCollection.TfsTeamProjectCollection(Uri, IdentityDescriptor)

Bb286958.collapse_all(ja-jp,VS.110).gif認証される資格情報を使用して

ID を指定するに Team Foundation Server に扮する接続すると ICredentials のオブジェクトを使用できます。この計画は特別なアクセス許可が必要ではありませんが、ICredentials のオブジェクトを作成するためには ID のパスワードを取得必要があります。

新しい資格情報の処理にどの文書 Team Foundation Server に接続する際に、ICredentialsProvider の実装を指定できます。システムから電話が新しい資格情報を要求するためのときに指定する ICredentialsProvider の実装 ICredentials の対象によって指定された資格情報は、工程の実行に認証も承認されません。

資格情報のユーザーのダイアログを表示するには、新しい資格情報のユーザーを求めるにログイン ダイアログ ボックスを表示して ICredentialsProvider を実行する UICredentialsProvider クラスを使用できます。

サーバー レベル

コレクション レベル

Bb286958.collapse_all(ja-jp,VS.110).gif技術の組み合わせを使用して

Team Foundation Serverに接続するとき Team Foundation ID と認証される資格情報を使用できます。たとえば、A のアプリケーションは、ユーザーの資格情報で実行する場合があります。Team Foundation Serverに接続するときのユーザー 12 Z 対象の資格情報を使用して、ユーザー C に IdentityDescriptor を指定する場合があります。この場合、その接続による要求は、ユーザーの 12 Z 対象として認証されますが、C ユーザーに代わって実行されます。この適用される戦略のユーザーの 12 Z 対象は *** 別のユーザーに代わって要求を行います。*** のアクセス許可が必要です。

サーバー レベル

  • 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 上のチーム プロジェクトへの接続

TfsTeamProjectCollection の TfsConnection、TfsConfigurationServer およびクラスがあります。 Microsoft の Web サイト

バージョン管理 API の偽装を使用して TFS Microsoft の Web サイト。