Customize Team Build 2010 – Part 16: Specify the relative reference path

Posted on Ewald Hofman See other posts from Ewald Hofman
Published on Wed, 06 Apr 2011 14:56:44 +0200 Indexed on 2011/06/20 16:40 UTC
Read the original article Hit count: 642

Filed under:
|

In the series the following parts have been published

  1. Part 1: Introduction
  2. Part 2: Add arguments and variables
  3. Part 3: Use more complex arguments
  4. Part 4: Create your own activity
  5. Part 5: Increase AssemblyVersion
  6. Part 6: Use custom type for an argument
  7. Part 7: How is the custom assembly found
  8. Part 8: Send information to the build log
  9. Part 9: Impersonate activities (run under other credentials)
  10. Part 10: Include Version Number in the Build Number
  11. Part 11: Speed up opening my build process template
  12. Part 12: How to debug my custom activities
  13. Part 13: Get control over the Build Output
  14. Part 14: Execute a PowerShell script
  15. Part 15: Fail a build based on the exit code of a console application
  16. Part 16: Specify the relative reference path


As I have already blogged about, it is not intuitive how to specify the paths where the build server has to look for references that are stored in Source Control. It is a common practice to store 3rd party libraries in Source Control, so they are available to everyone, everyone uses the same version of the libraries and updating a library can be done centrally.

In Team Build 2010 these paths are specified as a parameter for MSBuild. What we will do in this post is building the values for this parameter based on the values in an argument. You are now pretty aware how to customize the build template, so let’s do the modifications in another way. Instead of opening the xaml file in the workflow designer, we open it in the XML editor. You can open it in the XML Editor by either selecting the Open with menu (see the context menu), or by choosing the View code option.

To add this functionality we need to:

  1. Specify a new argument
  2. Add the argument to the metadata
  3. Build the absolute paths for the references and add these paths to the MSBuild arguments

1. Specify a new argument

Locate at the top of the document the Members (which are the arguments) of the XAML

image

and add the following line

<x:Property Name="ReferencePaths" Type="InArgument(s:String[])" />

image

2. Add the argument to the metadata

Then locate the line

<mtbw:ProcessParameterMetadataCollection>

and paste the following line

<mtbw:ProcessParameterMetadata Category="Misc" Description="The list of reference paths, relative to the root path in the Workspace mapping." DisplayName="Reference paths" ParameterName="ReferencePaths" />
image

3. Build the absolute paths for the references and add these paths to the MSBuild arguments

Now locate the place where the assignments are done to the variables used in the agent.

image

And add the following lines after the last Assign activity

        <Sequence DisplayName="Initialize ReferencePath" sap:VirtualizedContainerService.HintSize="464,428">
          <Sequence.Variables>
            <Variable x:TypeArguments="x:String" Name="ReferencePathsArgument">
              <Variable.Default>
                <Literal x:TypeArguments="x:String" Value="" />
              </Variable.Default>
            </Variable>
          </Sequence.Variables>
          <sap:WorkflowViewStateService.ViewState>
            <scg:Dictionary x:TypeArguments="x:String, x:Object">
              <x:Boolean x:Key="IsExpanded">True</x:Boolean>
            </scg:Dictionary>
          </sap:WorkflowViewStateService.ViewState>
          <ForEach x:TypeArguments="x:String" DisplayName="Iterate through the paths" sap:VirtualizedContainerService.HintSize="287,206" mtbwt:BuildTrackingParticipant.Importance="Low" Values="[ReferencePaths]">
            <ActivityAction x:TypeArguments="x:String">
              <ActivityAction.Argument>
                <DelegateInArgument x:TypeArguments="x:String" Name="path" />
              </ActivityAction.Argument>
              <Assign x:TypeArguments="x:String" DisplayName="Build ReferencePath argument" sap:VirtualizedContainerService.HintSize="257,100" mtbwt:BuildTrackingParticipant.Importance="Low" 
To="[ReferencePathsArgument]" Value="[If(String.IsNullOrEmpty(ReferencePathsArgument), &quot;&quot;, ReferencePathsArgument + &quot;;&quot;) + IO.Path.Combine(SourcesDirectory, path)]" />             </ActivityAction>           </ForEach>           <Assign DisplayName="Append the reference paths to the MSBuild Arguments" sap:VirtualizedContainerService.HintSize="287,58">             <Assign.To>               <OutArgument x:TypeArguments="x:String">[MSBuildArguments]</OutArgument>             </Assign.To>             <Assign.Value>               <InArgument x:TypeArguments="x:String">[String.Format("{0} /p:ReferencePath=""{1}""", MSBuildArguments, ReferencePathsArgument)]</InArgument>             </Assign.Value>           </Assign>         </Sequence>

Now you can use the template to specify the paths relative to SourcesDirectory.


You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.


© Ewald Hofman or respective owner

Related posts about VS 2010

Related posts about Team Build