views:

252

answers:

4

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.

+2  A: 

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.

Pedro
+2  A: 

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"

Adam Fyles
(+1) I was unaware of the MSBuildExtensionsPath, which according to documentation, "is a useful place to put custom target files."http://msdn.microsoft.com/en-us/library/ms164309.aspx
Pedro
+2  A: 

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

More details in this answer

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.

epaulsen
+2  A: 

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>&quot;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\tf&quot;</TxTf>

  <WorkingDirectory>C:\YourPathHere<WorkingDirectory>
  <CustomProjTFSDir>&quot;$/YourProj/YourCustomProjPath&quot;</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

Vaccano