Tuesday, July 15, 2008

How to extending default MSBuild script for Teambuild

I have been configuring and using Cruise Control .NET and NANT combination for my last project in my company. Everyone loves it, it takes only 10 minutes from the code check-in to generate the final deployable binaries. I even setup the an auto-deploy project so that when the latest code is generated, it will automatically deploy under the IIS. Everyone can monitor the project status via the little green icon in the system tray.

Since I was the person who was most familiar with compile/build process in the team, I undertook the task to setup a new build system and convert all existing projects into Team Foundation Server (TFS). Since I do not like hybrid solution, I set out to just use the MSBuild functionality. It was quite easy to configure the MSBuild agent. I did it with the following steps:

1. Install the Team Foundation Build from the TFS CD.
2. Make sure that you are granted access rights to Build Services via the Project Security dialog box.
3. Right-mouse click on the Builds and select Manage Build Agents and add a build agent that setup in step 1.
4. Right-mouse click on the Builds and select Add new Build Definition.
5. Under the Project File menu, you can have the TFS to create a default build file.
6. Complete the rest of menu options and click OK to save the changes.

Now you have a newly created build definition and you can launch it by right-mouse clicking and selecting Queue New Build. You should have the compiled binary files in the drop location in 5 minutes if your project is not too big.

The next thing comes is how to further configure it. Specifically there are 2 things I would like to do:

1. replace some place holder in the source files before compile
2. run the WISE setup module to create  final MSI files for distribution.

After a little bit digging in the Microsoft.TeamFoundation.Build.targets file, I found all the extension points that are available as the following. By create 2 targets (AfterGet and PackageBinaries) in the newly-created build definition file, I could archieve what I what to do here.



  <!-- Override this target to execute custom tasks before EndToEndIteration -->
  <Target Name="BeforeEndToEndIteration" />

  <!--
       Override this target to execute a task for customizing the build number and/or drop location.
       Make sure that the task outputs properties with the names 'BuildNumber' and/or 'DropLocation'.
    -->
  <Target Name="BuildNumberOverrideTarget" />

  <!--
       Override this target to execute a task for customizing the build number and/or drop location.
       Make sure that the task outputs properties with the names 'BuildNumber' and/or 'DropLocation'.
    -->
  <Target Name="BuildNumberOverrideTarget" />

  <!-- Override this target to execute custom tasks before clean -->
  <Target Name="BeforeClean" />

  <!-- Override this target to execute custom tasks after clean -->
  <Target Name="AfterClean" />

  <Target Name="BeforeCleanConfiguration" />
  <Target Name="AfterCleanConfiguration" />

  <!-- Override this target to execute custom tasks before cleaning an individual solution -->
  <Target Name="BeforeCleanSolution" />

  <!-- Override this target to execute custom tasks after cleaning an individual solution -->
  <Target Name="AfterCleanSolution" />

  <!-- Override this target to execute custom tasks before workspace initialization -->
  <Target Name="BeforeInitializeWorkspace" />

  <!-- Override this target to execute custom tasks after workspace initialization  -->
  <Target Name="AfterInitializeWorkspace" />

  <!-- Override this target to execute custom tasks before getting sources -->
  <Target Name="BeforeGet" />

  <!-- Override this target to execute custom tasks after getting sources -->
  <Target Name="AfterGet" />

  <!-- Override this target to execute custom tasks before labeling sources -->
  <Target Name="BeforeLabel" />


  <!-- Override this target to execute custom tasks after labeling sources -->
  <Target Name="AfterLabel" />


  <!-- Override this target to execute custom tasks before compilation -->
  <Target Name="BeforeCompile" />

  <!-- Override this target to execute custom tasks after compilation -->
  <Target Name="AfterCompile" />

  <!-- Override this target to execute custom tasks before the compilation of an individual configuration -->
  <Target Name="BeforeCompileConfiguration" />

  <!-- Override this target to execute custom tasks after the compilation of an individual configuration -->
  <Target Name="AfterCompileConfiguration" />

  <!-- Override this target to execute custom tasks before the compilation of an individual solution -->
  <Target Name="BeforeCompileSolution" />


  <!-- Override this target to execute custom tasks after the compilation of an individual solution -->
  <Target Name="AfterCompileSolution" />

  <!-- Override this target to execute custom tasks before associating changesets and updating work items -->
  <Target Name="BeforeGetChangesetsAndUpdateWorkItems" />

  <!-- Override this target to execute custom tasks after associating changesets and updating work items -->
  <Target Name="AfterGetChangesetsAndUpdateWorkItems" />


  <!-- Override this target to execute custom tasks before running tests -->
  <Target Name="BeforeTest" />


  <!-- Override this target to execute custom tasks after running tests -->
  <Target Name="AfterTest" />

  <!-- Override this target to execute custom tasks before the testing of an individual configuration -->
  <Target Name="BeforeTestConfiguration" />

 <!-- Override this target to execute custom tasks after the testing of an individual configuration -->
  <Target Name="AfterTestConfiguration" />

  <!-- Override this target to generate documentation. -->
  <Target Name="GenerateDocumentation" />

  <!-- Override this target to package all binaries for deployment. -->
  <Target Name="PackageBinaries" />

  <!-- Override this target to execute custom tasks before copying files to the drop location -->
  <Target Name="BeforeDropBuild" />

  <!-- Override this target to execute custom tasks after copying files to the drop location -->
  <Target Name="AfterDropBuild" />

  <!-- Override this target to execute custom tasks before the BuildBreak target -->
  <Target Name="BeforeOnBuildBreak" />

  <!-- Override the target to execute custom tasks after associating changesets on a build break -->
  <Target Name="AfterGetChangesetsOnBuildBreak" />

  <!-- Override the target to execute custom tasks before associating changesets on a build break -->
  <Target Name="BeforeGetChangesetsOnBuildBreak" />

  <!-- Override the target to execute custom tasks after associating changesets on a build break -->
  <Target Name="AfterGetChangesetsOnBuildBreak" />

  <!-- Override this target to execute custom tasks before work item creation -->
  <Target Name="BeforeCreateWorkItem" />

  <!-- Override this target to execute custom tasks after work item creation-->
  <Target Name="AfterCreateWorkItem" />



No comments: