Examining Get Task in TeamBuild
TeamBuild implemented ‘Get’ task for syncing sources. This task is same as ‘tf get’ , the command line utility to sync sources.
Properties Supported by Get Task
Workspace |
The workspace used to get sources |
Version |
You can specify a version by:
by default, it is ‘T’, get latest sources. |
FileSpec |
items that need to be fetched. It is ‘*’, by default |
Recursive |
Recursively retrieves all items that match your filespec |
Force |
Overwrite files |
The default build type uses this task to get the latest sources. However, you can very easily customize Get task to sync what you want. To do this, you will need to override the CoreGet target implemented in TeamBuild targets file Microsoft.TeamFoundation.Build.targets. I typically copy a target that I want to override into TfsBuild.proj of my build type and make changes appropriately. In this case, I copied CoreGet target into my TfsBuild.proj and played with it. I’m providing some examples below. This is a very powerful task. You can use the options Version and FileSpec in conjuction to get any sources
of any version.
Getting Labled Sources
The following example gets the sources labeled with “Beta1” and builds.
<Target Name="CoreGet"
Condition=" '$(IsDesktopBuild)'!='true' "
DependsOnTargets="$(CoreGetDependsOn)" >
<Get
Condition=" '$(SkipGet)'!='true' "
Workspace="$(WorkspaceName)"
Recursive="$(RecursiveGet)"
Version="LBeta1"
Force="$(ForceGet)" />
<!-- Label all files in the workspace to identify sources used in this build -->
<Label
Condition=" '$(SkipLabel)'!='true' "
Workspace="$(WorkspaceName)"
Name="$(BuildNumber)"
Version="W$(WorkspaceName)"
Files="$/$(TeamProject)"
Recursive="true" />
</Target>
Getting a Particular Changeset into TeamBuild
The following example gets the sources labeled with “Beta1” and gets Porgram.cs that was checked in with changeset 26.
<Target Name="CoreGet"
Condition=" '$(IsDesktopBuild)'!='true' "
DependsOnTargets="$(CoreGetDependsOn)" >
<Get
Condition=" '$(SkipGet)'!='true' "
Workspace="$(WorkspaceName)"
Recursive="$(RecursiveGet)"
Version="LBeta1"
Force="$(ForceGet)" />
<Get
Condition=" '$(SkipGet)'!='true' "
FileSpec="$/ScoutingTest/HelloWorld/Program.cs"
Workspace="$(WorkspaceName)"
Recursive="$(RecursiveGet)"
Version="C26" />
<!-- Label all files in the workspace to identify sources used in this build -->
<Label
Condition=" '$(SkipLabel)'!='true' "
Workspace="$(WorkspaceName)"
Name="$(BuildNumber)"
Version="W$(WorkspaceName)"
Files="$/$(TeamProject)"
Recursive="true" />
</Target>
Namaste!