I am trying to set up a common.targets file with some common msbuild targets I want to use in my team builds and therefore import into my TFSBuild.proj files. I am wondering what is the best way to achieve this? Do I need to store common.targets right next to each TFSBuild.proj file and therefore having duplicates of the targets file for each team build or is there another way? I would rather not put the targets file on each of the build machines.
The goal of a common .targets file is to reduce duplication of your scripts. If you have multiple copies of this file under source control, what happens when you need to change them (to update a .exe path maybe)? Personally, I prefer a separate location for common files that any/all other build scripts can reference. The only downside to this is you will likely be hard-coding the path to this file.
You could store them alongside the MS targets in $Volume\Program Files\MSBuild. The advantage of doing this is that you can create a relative path using the built in know metadata "$(MSBuildExtensionsPath)\Path\To\Your\Targets"
Team Build has a bootstrapper phase before the TFSBuild.proj is invoked in which only the TFSBuild.proj and other files in the same directory is downloaded from source control. So if you want your targets file to be under source control, you need to put it at the same location as the TFSBuild.proj
I have never tried it, but you might be able to put the targets file on a network share, and import it using a unc share. Something like
<Import Project="\\anothermachine\share\something.targets"/>
But that would require that the build account and all people running desktop builds have access to that network share.
Put it in a common location that you like in source control. Prior to using the targets, do a get from your TFSBuild.proj file like this:
<PropertyGroup>
<!--Path to the TFS Command Line (used for checkin and out)-->
<TxTf>"C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf"</TxTf>
<WorkingDirectory>C:\YourPathHere<WorkingDirectory>
<CustomProjTFSDir>"$/YourProj/YourCustomProjPath"</CustomProjTFSDir>
</PropertyGroup>
<Exec WorkingDirectory="$(WorkingDirectory)"
Command="$(TxTf) get $(CustomProjTFSDir)"/>
The key to this working is to setup a Workspace for your build agent user that points to your custom stuff. This directory should NOT be in the same space as your normal builds.
Vaccano