Export (0) Print
Expand All

Customize your build process template

If you need your build process to do more than what the default template can do, you can customize the build process template to follow your own Windows Workflow Foundation (WWF) instructions. Your instructions can run .NET Framework code that is implemented in CodeActivity objects. You can run activities that are built into Team Foundation Build (TFBuild), offered by third parties, or if necessary, built by you.

Tip Tip

If your custom build process functionality can be coded in a Windows batch file or a PowerShell script, you can upload your script and run it as part of your build process. This approach might be quicker and simpler than creating a custom build process. See Run a script in your build process.

Before you implement your instructions, extract a copy of the default template from your Team Foundation server and add it to a Visual Basic code project.

Important note Important

Are you working in a Git icon Git team project? Do you plan to upload build process activity binaries? If so, storing binaries (especially many revisions to large files) can balloon the size of your Git repository. We recommend that you store your custom build process binaries in a repository that is separate from the code from which you build your app. You can either create a separate team project for your build processes, or you can create an additional repository in your existing team project.

  1. Connect (Keyboard: Ctrl + 0, C) to the team project (and if appropriate, the Git icon Git repository) where you plan to store your build process source.

  2. Create a new code project (Keyboard: Keyboard: Ctrl + Shift + N).

    Specifically, create a new solution (for example, BuildProcessSource) that contains a new Visual Basic workflow activity library code project (for example, Templates). Add the solution to a new directory under version control in an understandable location.

    TFVC icon TFVC example: C:\Users\YourName\Source\Workspaces\FabrikamTFVC\BuildProcessTemplates\

    Git icon Git example: C:\Users\YourName\Source\Repos\BuildProcesses\

    Create a code project to contain the new template

    Why do I need a code project to edit my template?

  3. On the builds page (Keyboard: Ctrl + 0, B), create or edit a build definition.

    New Build Definition or Edit Build Definition
  4. Download a copy of the default template. Save your new template in the same folder that contains the code project you created earlier in this procedure

    TFVC icon TFVC example: C:\Users\YourName\Source\Workspaces\FabrikamTFVC\BuildProcessTemplates\BuildProcessSource\Templates

    Git icon Git example: C:\Users\YourName\Source\Repos\BuildProcesses\BuildProcessSource\Templates

    Download link on build definition Process tab

    Save As dialog box
  5. In solution explorer (Keyboard: Ctrl + Alt + L), add the template to your Templates project.

    Add the build process template file to the project

    Add Existing Item dialog box

    You don’t need the Activity1.xaml file, so you can delete it if you want.

  6. Set the Build Action property of your template to Content.

    Set the Build Action to Content
  7. Add the following references to your Templates code project:

    How do I add these references to the code project?

    Save the code project.

  8. Implement a “Hello World!” message so that after you check in and run the template you can be confident you’ve got it working. To do this, drag a WriteBuildMessage activity into your workflow and set its BuildMessageImportance property to Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High.

    Added WriteBuildMessage activity to template
  9. Save the template and upload your new solution. Either check in pending changes if you are in TFVC icon TFVC (Keyboard: Ctrl + 0, P), or commit (Keyboard Ctrl + 0, G) and push them if you are in Git icon Git.

    Uploading the changes using TFVC or Git

After you have uploaded a custom build process template to your team project as explained above, you can use the template from your build definitions.

  1. On the builds page (Keyboard: Ctrl + 0, B), create or edit a build definition.

  2. On the build definition Process tab, choose Show details Show details, and then choose New.

    Build definition, Process tab, New button
  3. After you choose New:

    • TFVC: Type or browse to the path to the template on your Team Foundation Server.

    • Git: Type or browse to the path to the template on your dev machine.

  4. After you specify the path to the template, you can select it from the list.

    CustomTemplate selected in build definition
  5. If you are creating a new build definition, select the solution you are building and specify the staging location and any other options you need. See Create or edit a build definition. When you are finished, save the build definition.

  6. On the builds page (Keyboard Ctrl + 0, B), queue the build.

    Queuing a build from the builds page
  7. After the build has completed, view the results to verify that your customized workflow ran as you expected.

    "Hello World!" message appears in build log

A: You should edit templates from within a code project because

  • Problems can occur when you try to edit a template outside the context of a code project.

  • Problems can occur unless you develop your build process activity in the same solution as your build process templates. By working this way, when you need to use one of your activities in your process template, the activity is available in the workflow designer toolbox. However, you must keep the source code for your activities in a separate code project from the one that contains your build process templates. See Use and develop custom build process activities.

A: Use the reference manager to add references to

View the code project references and open reference manager.

Custom template code project references

Reference Manager dialog box

Browse to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0 and then select and add:

Select the files to reference dialog box

Reference Manager dialog box

A: Yes. You can register a template with more than one team project. This capability means that you can share a build process across any team project in the team project collection that contains your template.

A: If you need to modify a template, you should plan to review all build definitions that are based on the template and correct them after you have completed your changes to the template. If you do not do this, your build definitions might fail or function in an unexpected way.

A: If you decide to delete a build process template, first make sure that you locate and delete all build definitions that are based on the template. When you delete the template, any remaining build definitions based on the template will no longer function.

A: A few common causes of some errors:

  • TF215097: Can appear if your custom activity is missing a required attribute or if you try to edit your template in the same code project that contains your custom activities.

  • MSBuild error XC1014: Can appear if you don’t set the Build Action of your template to Content.

If you get one of the above errors, make sure you have not missed one of the steps in the above procedures.

You might also find this topic helpful: Diagnose problems in your build.

Show:
© 2014 Microsoft