Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you do a TFS get without needing a workspace?

Tags:

tfs

I'm trying to change our build scripts from using SourceSafe to TFS without using MsBuild (yet).

One hiccup is that the workspace directory is renamed and archived by the scripts, which makes TFS think it doesn't need to get any files. Even with the /force flag it just gets the directories without getting the source files.

I am currently using

TF.exe get "Product/Main/Project1"  /force /recursive /noprompt

To save me managing workspaces in the scripts or using intermediate directories, does anyone know of a command that can get directories and code without needing a workspace?

like image 215
Matt Avatar asked Jan 17 '11 11:01

Matt


2 Answers

It's not possible to run a tf get without a workspace. The reason is that the server needs to know the mapping between the server paths and the local paths.

If you are working with a large number of files, it is not a good idea to:

  1. Create & Delete a new workspace every time
  2. Or, Create a new workspace (and then never delete it)

The reason for this is that every time you do a Get, the server keeps track of which files, at which versions were downloaded to which workspace. If you never clean up these workspaces, then the table that stores this information will grow over time.

Additionally, if you are creating & deleting a workspace all the time, the server has to write all these rows, then delete them when you are done. This is unnecessary.

You really should try and reuse the same workspace each time. If you do, the server is very efficient about only sending you files that have changed since you last downloaded them. Even if your build is moving from one branch to another, you can use tf get /remap which is sometimes more efficient if the branches share common files.

Although it doesn't solve your problem, it is possible to list files and download files without a workspace.

To list files:

tf dir $/Product/Main/Project1 /R

To download a file:

tf view $/Product/Main/Project1/file.cs

With a creative batch file, you can string these two together with a FOR command. However I would recommend trying to solve your workspace problem first, since that is the way that TFS was intended to be used.

like image 95
Grant Holliday Avatar answered Oct 23 '22 02:10

Grant Holliday


A workspace is a mapping between the source repository location and the filesystem location, so no you can't get away with not using a workspace. But you can easily set up and tear down a workspace when you need to.

Here is a simple TFS task i use to get my database source files from TFS prior to doing some text substitutions and building them into a database update package. You can easily translate this to whatever syntax your current build scripts require:

<Target Name="GetDatabaseSources">
    <!-- clean out the folder before doing the fresh get of the database sources -->
    <Folder.CleanFolder Path="$(DatabaseBuildBaseLocation)" Force="true"/>

    <!-- create a workspace for the database source of the product -->
    <CallTarget Targets="CreateDatabaseSourceWorkspace" />
    <!-- get the database sources for the product -->
    <Get TeamFoundationServerUrl="$(TeamFoundationServerUrl)" Workspace="$(DatabaseSourceWorkspaceName)" Recursive="true" Version="$(DatabaseSourceVersion)" Force="true" />
    <!-- delete the workspace -->
    <Exec Command="$(Tf) workspace /delete $(DatabaseSourceWorkspaceName) /server:$(TeamFoundationServerUrl) /noprompt " ContinueOnError="true" />
</Target>

<!-- creates and maps a temporary workspace for the database source of the product -->
<Target Name="CreateDatabaseSourceWorkspace">
    <Exec Command="$(Tf) workspace /delete $(DatabaseSourceWorkspaceName) /server:$(TeamFoundationServerUrl) /noprompt " ContinueOnError="true" />
    <Exec Command="$(Tf) workspace /new $(DatabaseSourceWorkspaceName) /server:$(TeamFoundationServerUrl) /noprompt" />
    <Exec Command="$(Tf) workfold /unmap /workspace:$(DatabaseSourceWorkspaceName) $/" />
    <Exec Command="$(Tf) workfold /map /workspace:$(DatabaseSourceWorkspaceName) /server:$(TeamFoundationServerUrl) $(DatabaseSourceLocation) &quot;$(DatabaseBuildBaseLocation)&quot;"  />
</Target>

TFS is your source repository, but you didn't explicitly mention what your build scripts were designed for. You really should migrate them to a TFS build script, then you can simplify your build, for example you won't have to worry about mapping workspaces or getting the latest source code because TFS does that for you, all you have to worry about is any custom build steps and possibly archiving your build results.

like image 45
slugster Avatar answered Oct 23 '22 02:10

slugster