17

What I want to do is get a specific version of a file from TFS to a location other than my workspace using the command line (either tf.exe or powershell)

I want to do this so that it doesn't affect the files in my workspace, and places the file into a release folder.

tf.exe only seems to support getting a file to your workspace.

I haven't found a way to do it with Powershell either.

Can anyone help me out?

Danny Frencham
  • 931
  • 1
  • 8
  • 17

1 Answers1

24
rem tf.exe
tf view $/path/to/file.txt /version:1234 > %temp%\file.txt

# powershell
$tfs = get-tfsserver $hostName -all
$tfs.vcs.DownloadFile($serverPath, $fileName)

# even better: manipulate entirely in-memory
$item = $tfs.vcs.GetItem($serverPath)  # tons of GetItem(s) overloads available
$contents = ( [io.streamreader]$item.DownloadFile() ).ReadToEnd()
$contents | ? { some-condition } | do-coolstuff
Richard Berg
  • 20,629
  • 2
  • 66
  • 86
  • 6
    Instead of "tf view xx > %temp\file.text" you can also use the /output argument. The command then becomes: tf view $/path/to/file.txt /version:1234 /output:"%temp%\file.txt" – Ewald Hofman Jan 24 '11 at 04:18
  • There needs to be a way to do this via the GUI - crazy – PeterX Feb 12 '16 at 02:26