MsBuild is the new build engine that Microsoft provides with Visual Studio 2005. The MsBuild engine is used as well in the Team Build environment that is part of Microsoft Team Foundation Server.
To learn more about MsBuild, visit this site.
Creating a new build type
Visual Studio 2005 provides a wizard that can be used to create a new team build. Through the menu: ‘Build’ -> ‘New Team Build Type’ this wizard can be started. The wizard will collect some configuration information, like the name the new built type, the name of the build server, the build directory to use and a set of solutions that must be build. When the wizard is finished, it will have created 3 files:
These files are automatically added to the Team Foundation Version Control repository.
A folder ‘Team Builds’ is created in the root of the Team Project folder. This folder will contain a folder for each build type that is created, containing these 3 files.
The TFSBuild.proj file
The TFSBuild.proj file is the MsBuild project file that will be executed when a build is run. When you need to customize your build, this is the place to add customization.
Default this file will only contain some configuration information. When reading past all the comment that is generated, the first real statement in the file is an import statement. This statement will include a file which contains the target definitions that will be executed during the build. I will talk about this file further down this post.
Next you will see a <ProjectExtensions>element which contains the description, if any, describing the type of build and the name of the build machine that will be used.
Following this element is a property group that contains all kind of configuration information needed for the build. For example: a flag specifying when to run the static code analyses.
Next you will see an item group. This item group contains a list of solutions that will be build. (The order in which the solutions are defined, is the order in which the solutions are processed.)
Two more item groups are defined, providing some additional configuration information.
The TFSBuild.rsp file
In the TFSBuild.rsp file, you can specify additional options that should be passed to the build engine. For more information, look here.
The WorkspaceMapping.xml file
The WorkspaceMapping.xml file contains the mapping between the folder structure in Team Foundation Version Control and the folder structure on disk. Depending on the selection made during the creation of the build type, the content of the file may differ. One or more <InternalMapping> elements are defined. These elements specify the mapping. The attribute ServerItem specifies the location in Team Foundation Version Control. The attribute LocalItem specifies the location on the local disk where the build will get the sources to. Note that the path will start with the location where Visual Studio 2005 is installed. This part of the path will be replaced during the build process with the build directory specified in the TFSBuild.proj file.
Customizing a Team Build
Team Foundation Build offers a way to customize and extend the default build process. Team Foundation Build consists, amongst other files, of a file named: Microsoft.TeamFoundation.Build.targets. This file defines the different targets (steps in the build cycle) that can be executed.
Some of these targets are already implemented by Microsoft. Some other targets are provided for us developers to extend the build process. (For a list of targets see this article on the MSDN site.)
A target is recognized by its name. When multiple targets have the same name, MsBuild will only execute the target that was last defined in the files. Let’s look at the following example:
The MsBuild project file MyProject.proj imports the targets file My.targets. The default target is
Team build will be started with the TFSBuild.proj file, this file imports the Microsoft.TeamFoundation.Build.targets targets file. Any target that is redefined in the TFSBuild.proj file, after the import statement, is automatically executed by the build engine. It is therefore recommended to add the customized targets to the TFSBuild.proj file. This way, the Team Build files are not changed and could be updated (via an update from Microsoft) without loosing the customizations that were made.
Customization of Team Build can be done in different ways. It might be enough to add some MsBuild code to accomplish the custom task you need.
Sometimes it might be necessary to do some complex or very specific tasks that can not be accomplished with the default MsBuild tasks that are available. In that case you can build your own task. For more information on how to build your own MsBuild task, see this article.
Hopes this helps,