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: 639
VS 2010
|Team Build
In the series the following parts have been published
- Part 1: Introduction
- Part 2: Add arguments and variables
- Part 3: Use more complex arguments
- Part 4: Create your own activity
- Part 5: Increase AssemblyVersion
- Part 6: Use custom type for an argument
- Part 7: How is the custom assembly found
- Part 8: Send information to the build log
- Part 9: Impersonate activities (run under other credentials)
- Part 10: Include Version Number in the Build Number
- Part 11: Speed up opening my build process template
- Part 12: How to debug my custom activities
- Part 13: Get control over the Build Output
- Part 14: Execute a PowerShell script
- Part 15: Fail a build based on the exit code of a console application
- 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:
- Specify a new argument
- Add the argument to the metadata
- 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
and add the following line
<x:Property Name="ReferencePaths" Type="InArgument(s:String[])" />
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" />
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.
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), "", ReferencePathsArgument + ";") + 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