TFSBuild.proj and Importing External Targets

后端 未结 3 902
臣服心动
臣服心动 2021-01-12 11:18

We want to store our overridden build targets in an external file and include that targets file in the TFSBuild.proj. We have a core set steps that happens and would like to

相关标签:
3条回答
  • 2021-01-12 11:59

    The Team Build has a "bootstrap" phase where everything in the Team Build Configuration folder (the folder with TFSBuild.proj) is downloaded from version control. This is performed by the build agent before the build agent calls MSBuild.exe telling it to run TFSBuild.proj.

    If you move your targets file from under SolutionRoot and place it in your configuration folder alongside the TFSBuild.proj file you will then be able to import it in your TFSBuild.proj file using a relative import statement i.e.

    <Import Project="myTeamBuild.targets"/>
    

    If these targets rely on any additional custom MSBuild task assemblies then you can also have them in the same folder as your TFSBuild.proj file and you can reference them easily using a relative path.

    Note that in TFS2008, the build configuration folder defaults to being under $/TeamProject/TeamBuildTypes however, it does not have to be there. It can actually live in a folder that is inside your solution - and can even be a project in your solution dedicated to Team Build. This has several advantages including making branching of the build easier. Therefore I typically have my build located in a folder like this:

    $/TeamProject/main/MySolution/TeamBuild
    

    Also note that by default, during the bootstrap phase of the build, the build agent will only download files that are in the build configuration folder and will not recurse down into any subfolders. If you wanted it to include files in subfolders during the bootstrap phase then you can set the following property in the appSettings of the tfsbuildserver.exe.config file on the build agent machines (located in %ProgramFiles%\Visual Studio 9.0\Common7\IDE\PrivateAssemblies)

    <add key="ConfigurationFolderRecursionType" value="Full" />
    

    Note that if you had multiple build agents you would have to remember to set this setting on all of the machines, and it would affect every build performed by that build agent - so really it is best just to keep the files in the root of the build configuration folder if you can.

    Good luck,

    Martin.

    0 讨论(0)
  • 2021-01-12 12:11

    If the targets should only be run when TFS is running the build and not on your local development machines, you can put your targets file in the folder for the build itself and reference it with:

    <Import Project="$(MSBuildProjectDirectory)\my.team.build.targets.proj" />
    

    However, if you want the targets to run for all builds, you can set it up so that the individual projects reference it by adding something like:

    <Import Project="$(SolutionRoot)/libs/my.team.build/my.team.build.targets" Condition="Exists('$(SolutionRoot)/libs/my.team.build/my.team.build.targets')" />
    

    On my project we actually use both of these, the first allows us to customize the nightly builds so we can do extra steps before and after running the full solution compile, and the second allows project-by-project customization.

    0 讨论(0)
  • 2021-01-12 12:16

    If you create an overrides target file to import and call it something like TeamBuildOverrides.targets and put it in the same folder in source control where TFSBuild.proj lives for your Build Type, it will be pulled first and be available for import into the TFSBuild.proj file. By default, the TFSBuild.proj file is added to the TeamBuildTypes folder in Source Control directly under the root folder of your project.

    use the following import statement in your TFSBuild.proj file:

    <Import Project="$(MSBuildProjectDirectory)\TeamBuildOverrides.targets" />
    

    Make sure you don't have any duplicate overrides in your TFSBuild.proj file or the imported overrides will not get fired.

    0 讨论(0)
提交回复
热议问题