Thursday, December 20, 2012

Downloading Files from TFS

There are many ways to deploy FIM, but I always try to start deployments from files that are version controlled by TFS.  Once you’ve stored your deployment scripts in TFS, you need to get them onto the FIM computer.  I typically do this by copying files, but have been thinking of trying a different approach – taking the files directly from TFS.

Turns out you don’t need Visual Studio installed to get files from TFS version control, just a single DLL.  With this approach you can have a small script on the server download the file from TFS directly onto the FIM computer.

Here’s the script snippet showing how to do it:

###

### I got this file from: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ReferenceAssemblies\v2.0

### NOTE: visual Studio does not need to be installed where this runs...

###

add-type -Path C:\TFSTest\Microsoft.TeamFoundation.VersionControl.Client.dll

 

###

### Connect to TFS Version Control

###

$TFS = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer('http://myTfsServer:8080/tfs/FIM')

$VersionControlServer = $TFS.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])

 

###

### Get an item from Source Control and download it

###

$TfsItem = $VersionControlServer.GetItem('$/MyFimProject/DeploymentScripts/DeployFimConfig.ps1')

$TfsItem.DownloadFile('c:\MyFimProject\DeployFimConfig.ps1')

 

 

2 comments:

Rahul1911 said...

This was helpful. Do you also have the option to choose an older version of the file as well.

I cant seem to get a hold of using the same method as in C# to pull the file with a specific version.

Craig Martin said...

Hi! I haven't tried that but am optimistic it would be possible via the object model.