Building a Specific Version with Team Build
Team Build by default gets the latest version of your sources (or tip) from source control. For the most part, this is probably the behavior you would want and expect. But not always - you might want to reproduce a particular build that got deleted, for example; or you might want to build your latest changest without including changes other users might have checked in.
Unfortunately, getting (and therefore building) a specific version from source control is not supported out of the box in Team Build version 1... The Get task used in Team Build (this can be found in Microsoft.TeamFoundation.Build.targets) looks like this:
<Target Name="CoreGet"
Condition=" '$(IsDesktopBuild)' != 'true' "
DependsOnTargets="$(CoreGetDependsOn)" >
<!-- Get all the latest sources from the given workspace-->
<Get Condition=" '$(SkipGet)' != 'true' "
Workspace="$(WorkspaceName)"
Recursive="$(RecursiveGet)"
Force="$(ForceGet)" />
</Target>
The Get task also a Version property that is not used here. It defaults to "T" , or the tip version. To get and build a specific version from source control, you will need to set this property.
There are several options here:
- You can override the CoreGet target in TfsBuild.proj.
- You can modify the CoreGet target in Microsoft.TeamFoundation.Build.targets directly.
- You can set the SkipGet property to true and override BeforeGet or AfterGet instead.
Modifying Microsoft.TeamFoundation.Build.targets is not a good idea - this would need to be done on every build machine, could get wiped out during an upgrade or installation repair, etc. Overriding CoreGet is usually not recommended either, since the CoreXX targets will almost certainly be changing in the next release of Team Build. In this case, however, overriding CoreGet (option 1) is essentially indistinguishable from setting SkipGet and overriding BeforeGet / AfterGet (option 3) and is simpler.
So - to override CoreGet in TfsBuild.proj, you will want to do something like the following:
<Target Name="CoreGet"
Condition=" '$(IsDesktopBuild)'!='true' "
DependsOnTargets="$(CoreGetDependsOn)" >
<!-- Get all the latest sources from the given workspace-->
<Get Condition=" '$(SkipGet)'!='true' "
Workspace="$(WorkspaceName)"
Recursive="$(RecursiveGet)"
Force="$(ForceGet)"
Version="$(VersionToGet)" />
</Target>
At this point, you just need to set the VersionToGet property to whatever version you would like to get. This can be done in all the normal MSBuild ways - via the command line (put a string in your TfsBuild.rsp file similar to /p:VersionToGet=<VersionSpec> ), declaratively in a PropertyGroup element, programmatically with a CreateProperty task, or via an environment variable.
To reproduce a particular build, you will typically want to set VersionToGet to a label-based version spec similar to "L<build number>" (unless you have modified your build process to use some other labeling scheme). For example, if you build number is "MyBuild_20060919.1" you could do something like this:
<PropertyGroup>
<VersionToGet>LMyBuild_20060919.1</VersionToGet>
</PropertyGroup>
Comments
- Anonymous
September 22, 2006
Aaron Hallberg has written a couple of posts about Team Build that started with questions from users.&nbsp;... - Anonymous
September 24, 2006
CoreGet is a core event, Can we Overriding this event ? Is this do can effect other work? - Anonymous
September 25, 2006
Tolong on An overview on Team Foundation Server Architecture.
Aaron Hallberg on Building a Specific... - Anonymous
September 25, 2006
CoreGet is indeed a core target, and normally we do not recommend overriding these. In certain cases, however, there is no other reasonable way to accomplish a goal in Team Build v1. Building a specific version is one of these cases - we simply did not provide the necessary extensibility points to accomplish this without overriding CoreGet or making some other change that amounts to the same thing.
If you choose to override a core target, you will want to make sure to examine any changes to the target in future releases of Team Build when upgrading to avoid breaking your build, missing out on some new functionality in the target, etc. - Anonymous
September 25, 2006
I have a question. I see only you can answer.
Is BeforeXXX and AfterXXX event default not done anything, only return true? These event are only given to the developer to write their code? - Anonymous
September 25, 2006
That is correct - the BeforeXX and AfterXX targets are provided as extensibility points for users. For a complete list of the targets users are encouraged to override, see the following blog post: http://blogs.msdn.com/buckh/archive/2006/08/09/team_build_extensibility.aspx. - Anonymous
September 13, 2007
Please check out the blog entry by Aaron http://blogs.msdn.com/aaronhallberg/archive/2006/09/19/building-a-specific-version-with-team-build.asp - Anonymous
June 26, 2008
In Team Build 2008 there is a property called GetVersion . Here’s what the description from Aaron Hallberg’s - Anonymous
December 24, 2008
关键字:Label,Changeset,datetime...在TeamBuild的时候我们经常有需求需要编译某个版本,例如某个Label,或者什么时候提交的,而不是最新提交的版本,在T...