TFS: Enable Team Project Portal script

If you don’t have SharePoint configured at the time that you upgrade your Team Foundation Server or when you attach a new TPC, then one of the things that you might be left with is this:

  • The Team Project is working fine
  • The SharePoint site is working fine
  • But they’re not linked or associated with each other as a Project Portal

Project Portal Settings in Visual Studio Team Explorer. The 'Enable team project portal' checkbox is not checked

Unfortunately (until now) the only way to link these two together again is to use Visual Studio to open up the Project Portal Settings for each team project and tick the box. If you have do to this for more than a few team projects on a server, it’s pretty tedious. 5 is about the limit of my patience, but I have seen customers do up to 100.





EnableProjectPortal.exe <tfs server url> <team project id> <sharepoint relative path> <owned web identifier>


EnableProjectPortal.exe http://localhost:8080/tfs/” “2eb9c8a2-2243-4897-ac88-602bef270dd5” “/sites/TailspinToysCollection/Tailspin Toys” “224C16E0-00DA-4C98-9042-3D21228B2511”

This console application will use the ICatalogService API to do the equivalent of the ‘[x] Enable team project portal’ checkbox. You will need to collect some information before you can use it, but at least you can build up a batch file and do lots of team projects at once.

Get a list of projects and their IDs

There’s plenty of different ways to get a list of Team Projects and their GUIDs, but this one is fine for a once off:

1. Open SQL Server Management Studio

2. Connect to Team Project Collection database (e.g. Tfs_DefaultCollection)

3. Run the following query:

SELECT project_name, project_id

FROM tbl_Projects

WHERE [state] = ‘WellFormed’

ORDER BY project_name

It should return something like this:



Tailspin Toys


Copy and paste this list into Excel

Get a list of the SharePoint sites and their WebIdentifier IDs

Once again, there’s more than one way to get this information other than going directly to the database. But for a once off like this, it will be fine:

1. Open SQL Server Management Studio

2. Connect to the SharePoint content database that holds your team sites (e.g. WSS_Content)

3. Run the following query:


FullUrl as ‘RelativePath’,

Id as ‘OwnedWebIdentifier’

FROM AllWebs

ORDER BY RelativePath

It should return something like this:











Paste this into somewhere else in your Excel workbook

Construct a mapping table

Now we need to map the team projects/team project IDs to sharepoint sites. Use Excel to construct a table with the following format:





Tailspin Toys


sites/TailspinToysCollection/Tailspin Toys






Now we can use this table construct the arguments for EnableProjectPortals.exe. You can use this formula in a new column to the right, in Excel:

=CONCATENATE(“EnableProjectPortal.exe “”http://localhost:8080/tfs/”” “””,B2,””” “””,C2,””” “””,D2,””””)

Repairing connections

Once all the portal settings have been established, you should open the Team Foundation Server Administration Console and choose “Repair Connections”.

This will make sure all the SharePoint permissions and properties are set correctly.

TFS Administration Console showing the Repair Connections link

Log for repairing the connection between TFS and SharePoint

At this point you are done and you have saved yourself or your customer a lot of tedious clicking.


The Code

All the thanks go to Phil (another Aussie expat on the TFS team) for this utility. I was just the beneficiary and now I’m the messenger.

Here’s the guts of it where we set up a dependency property in the ICatalogService between the team project and the SharePoint site.

var projectPortalNodes = teamProject.NodeReferences[0].QueryChildren(new Guid[] { CatalogResourceTypes.ProjectPortal }, true, CatalogQueryOptions.ExpandDependencies);

CatalogNode projectPortalNode = null;

if (projectPortalNodes.Count > 0)
  // It already exists, so lets overwrite/set with the values we want.
projectPortalNode = projectPortalNodes[0];
  // It doesn’t exist, so lets create it.
  projectPortalNode = teamProject.NodeReferences[0].CreateChild(CatalogResourceTypes.ProjectPortal, “Project Portal”);

// Set properties
projectPortalNode.Resource.Properties[“ResourceSubType”] = “WssSite”;
projectPortalNode.Resource.Properties[“RelativePath”] = sharePointRelativePath;
projectPortalNode.Resource.Properties[“OwnedWebIdentifier”] = sharePointOwnedWebIdentifier;

// BUG: Use the first sharepoint web resource. Doesn’t work with multiple.
projectPortalNode.Dependencies.SetSingletonDependency(“ReferencedResource”, sharepointWebAppResources[0].NodeReferences[0]);


Comments (2)

  1. harvin says:

    we've been looking for something like this for a very long time. With an enterprise deployment of more than 400 projects and regular moving around of collections, we;ve have to constantly redo the linking manually, a huge manual effort.Thanks!

  2. Jay Clarke says:


    Thanks for the article. I was wondering if there was a way to control the check/uncheck the portal settings for enabling a team project portal and link to process guidance? I have about 39 team sites that I am creating SharePoint sites for and I have everything scripted except this step. It would be nice to incorporate that step into my script instead of having to do the manual step.