Get a file from TFS without a workspace

August 17, 2006 at 2:23 am | In Team Foundation Server |

I’m currently working with a client to replace their Visual SourceSafe source code control system  with Team Foundation Server. Along the way we’re finding that we need to replace existing VSS customisations with their TFS equivalents.

One particular process uses batch scripts to grab the latest copy of a config file from VSS and copy it to a staging server.

Existing command

  • ss.exe Get $/Project/Config.xml

TFS equivalent

My first thought was “great! I can just use tf.exe get“, however tf.exe requires that a workspace be created before you can grab a copy of the file.

Fortunately Item.DownloadFile() lets you grab a file without creating a workspace.

// Do the download
Item item = versionControl.GetItem(tfsPathToDownload);
item.DownloadFile(destinationFileName);

TfsDownloadFile.exe

I’ve created a simple exe that can be used by your batch scripts to grab the latest copy of a file without creating a workspace. Optionally you can specify an output filename to write to.

Usage

TfsDownloadFile [server] [path] <output filename>

TfsDownloadFile http://server:8080/ $/TeamProject/config.xml

Get the source

Download from the ProjectDistributor project page. Direct download v1.0 Source and Binaries here.

Feedback

Let me know if you find this useful by leaving a comment. Any feedback or suggestions are welcome.

5 Comments »

RSS feed for comments on this post. TrackBack URI

  1. Fantasic! Thanks for sharing. I looked an looked and could not find… until I hit this post. Thanks for the explanation and the code!

    Comment by nathan — February 1, 2007 #

  2. hi,how to checkout, checkin & checkout a file programmatically

    Comment by krish — July 12, 2007 #

  3. Hi Grant,

    You might remember me from your DEWR days, and I’m interested to know if it is possible to check out a whole directory without using a workspace.

    Cheers.

    Comment by Luke Elliott — December 12, 2007 #

  4. tf dir does not need a workspace, so in order to get a whole directory, use it to gather its contents into an array, running this utility on each.

    Would be nice to be able to get a speciffic version of an object using this tool.

    Regards
    Jon

    Comment by Jon J Bjarnason — April 23, 2008 #

  5. Jon - You could easily download the source, add another parameter and change:

    versionControl.GetItem(tfsPathToDownload) to:

    versionControl.GetItem(tfsPathToDownload, args[3])

    See:
    http://msdn2.microsoft.com/en-us/library/bb138927.aspx

    Comment by Grant Holliday — April 24, 2008 #

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.