In Team Build 2008 there is a property called GetVersion. Here’s what the description from Aaron Hallberg’s blog says about it:
GetVersion. Passed to the Version property of the Get task. Defaults to SourceGetVersion (see below), but can be overridden to retrieve a particular version from source control.
To use this property to build a previous version of the source code you have three options:
Additional MSBuild Parameters dialog
Queue a new build and in the “Additional MSBuild Parameters” box, put:
Where XXXX is the changeset you want to build. See screenshots here.
TFSBuild.rsp – MSBuild Response file
Or, put the same option in the TFSBuild.rsp (response) file. The contents of this file are passed as command line parameters to MSBuild.
Or, Add a property into the TFSBuild.proj Team Build project file.
You don’t have to specify a changeset either. You can specify any valid versionspec. See the versionspec heading under Command-Line Syntax for more options.
With TFS 2005 you would have needed to change the core implementation of Team Build.
See Aaron Hallberg’s “Building a Specific Version with Team Build” blog.
Another thing to keep in mind is – What version of TFSBuild.proj will you be using to build the previous version of the code? What I typically do is store the TFSBuild.proj file alongside the source code in the branch. That way when you branch the code and you need to make build script changes, they are isolated and merged back with the code changes.