Scott
Scott

Reputation: 2183

Connect Visual Studio 2012 to TFS 2012 programmatically

I'm building a base developer machine image such that when a new developer is added to the team, we can give the developer a machine which has all the tools installed and configured.

I'm trying to devise a way to connect Visual Studio to TFS via a PowerShell script or command line batch file, such that visual studio will use the developer's credentials to connect to the TFS server.

I understand that the new developer can open up visual studio, open up the Team menu, select connect to team foundation server... Add a Server to the Servers... dialog, then select the Team Projects and click Connect. However, this whole process is the process I'd like to automate.

I'm not looking for the code to do so, although it would be accepted. Instead, I'm looking for direction on where to locate the API calls for Visual Studio to modify this type of setting.

Upvotes: 3

Views: 1041

Answers (2)

Swoogan
Swoogan

Reputation: 5558

You can use the following code to do this:

# Add servers to vs 2012
Add-Type -AssemblyName 'Microsoft.TeamFoundation.Client, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

function Add-Collection([string]$url) {
    $uri = New-Object Uri($url)
    $ttpc = New-Object Microsoft.TeamFoundation.Client.TfsTeamProjectCollection($uri)
    $projs = [Microsoft.TeamFoundation.Client.RegisteredTfsConnections]::RegisterProjectCollection($ttpc)
}

Add-Collection -url 'http://mytfsserver:8080/tfs/DefaultCollection'

Note: if you have both VS 2010 and 2012 installed this will only add the registration to 2012.

Upvotes: 2

TimVK
TimVK

Reputation: 1146

Maybe this post can help you to find the answers. And otherwise you can try it with command prompt andtf.exe` that can be found in

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

Upvotes: 0

Related Questions