Using VS to get the URI for a Team Project

Someone asked a question today about getting the URI for a Team Project.  James Manning’s Team Project code sample showed how to do it using the API.  However, that was overkill in this case.  Bill Essary pointed out that you can select the Team Project in Team Explorer, right-click on it, and choose Properties (rather than right-click, you could just hit F4).  The Properties window shows the URI as the Url property (yes, apparently no one noticed that).

The URI you get will look something like the following.  All Team Foundation URI’s start with “vstfs:///” that will be tranlated to actual server URL’s as needed.


The URI isn’t needed for any normal day-to-day tasks.  Occasionally, you may have the need for it for some advanced admin activity.  TfsSecurity, for example, can accept Team Project URI’s for some options.

Comments (3)

  1. Anonymous says:

    I need the URI for a script.    Do you know of a command line way of getting the URI for a source project.   Is there a simple way using some already existing utility like TFSSecurity.exe or tf.exe to give this information.

  2. Buck Hodges says:

    I asked, and there does not seem to be a command line to return it. You would need to use something like the following.

    TfsTeamProjectCollection tpc = <get the tpc>

    ICommonStructureService svc = tpc.GetService<ICommonStructureService>();

    ProjectInfo[] projects = svc.ListProjects();

    foreach(ProjectInfo p in projects)


                   Console.WriteLine(“project name: ‘“ + p.Name + “’  project Url: ‘” + p.Uri);


  3. Anonymous says:

    This is in PowerShell but basically the same

    $pathToAss2 = "C:Program FilesMicrosoft Visual Studio 12.0Common7IDEReferenceAssembliesv2.0"

    $pathToAss4 = "C:Program FilesMicrosoft Visual Studio 12.0Common7IDEReferenceAssembliesv4.5"

    Add-Type -Path "$pathToAss2Microsoft.TeamFoundation.Client.dll"

    Add-Type -Path "$pathToAss2Microsoft.TeamFoundation.Common.dll"

    Add-Type -Path "$pathToAss2Microsoft.TeamFoundation.WorkItemTracking.Client.dll"

    Add-Type -Path "$pathToAss2Microsoft.TeamFoundation.VersionControl.Client.dll"

    Add-Type -Path "$pathToAss4Microsoft.TeamFoundation.ProjectManagement.dll"

    $CollectionUrl =  "http://…."

    $tfs = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($CollectionUrl)

    $StructureService = $Tfs.GetService("Microsoft.TeamFoundation.Server.ICommonStructureService3")

    $ProjectInfos = $StructureService.ListProjects();

    foreach($ProjectInfo  in $ProjectInfos)


       Write-Host (“project name: ‘“ + $ProjectInfo.Name + “’  project Url: ‘” + $ProjectInfo.Uri)