custom msbuild task to get changesets and workitems based on AreaPath

 

 

Objective of sample task

 

Get all the affected change sets between this build and the previous successful build that has the work items with Area Path according to input parameter specified in the .proj file.

 

You need to make the following changes in your tfsbuild.proj

 

1. Compile the code and create the assembly (dll)

2. check-in the task assembly in the build type folder (along with tfsbuild.proj file)

3. Add using task tag just before the <Import Project… statement. For example

<

UsingTask

TaskName="Microsoft.TeamFoundation.Build.Tasks.Samples.GetChangesetsWorkItemsList"

AssemblyFile="GetChangesetsWorkItemsList.dll" />

4. Disable the old gencheckinnotes task by setting the following property inside tfsbuild.proj

 

<

PropertyGroup>

<

SkipPostBuild>true</SkipPostBuild>

</

PropertyGroup>

5. Reset the old gencheckinnotes task on build break by redefining the target definition inside tfsbuild.proj –

<

Target Name="GetChangeSetsOnBuildBreak"

Condition=" '$(IsDesktopBuild)'!='true' " >

<!--

Get associated changesets even when build fails. Set the AreaPath property-->

<

GetChangesetsWorkItemsList

AssemblyPath="$(TeamBuildRefPath)"

Recursive="false"

AreaPath=""

TeamFoundationServerUrl="$(TeamFoundationServerUrl)"

BuildId="$(BuildNumber)"

CurrentLabel="L$(BuildNumber)$(LabelQueryScope)"

LastLabel="L$(LastGoodBuildNumber)$(LabelQueryScope)"

UpdateWorkItems="false"

ContinueOnError="true" />

</

Target>

6. Invoke the new task by redefining the target definition inside tfsbuild.proj –

<

Target Name="AfterCompile">

<

GetChangesetsWorkItemsList

AssemblyPath="$(TeamBuildRefPath)"

Recursive="true"

AreaPath="TeamProject1\Area 0"

TeamFoundationServerUrl="$(TeamFoundationServerUrl)"

BuildId="$(BuildNumber)"

CurrentLabel="L$(BuildNumber)$(LabelQueryScope)"

LastLabel="L$(LastGoodBuildNumber)$(LabelQueryScope)"

UpdateWorkItems="$(UpdateAssociatedWorkItems)"

ContinueOnError="true" />

</

Target>

7. Make sure to add the targets towards the end of the tfsbuild.proj (just before </Projects> tag)

Important Points about the custom task:-

1. If the area path is empty, then the task falls back to the default behavior where it will get all the change sets and the associated work items between the last successful build and the current build.

2. If the area path is invalid, you will not get any work item but we will not indicate that you have passed invalid/non existent area path.

3. If the area path is valid and recursive flag is set, then we will get all the change sets and the work items that belong to the area path note or its children.

4. If the area path is valid and recursive flag is not set, then we will get only the change sets and the work items that belong to the area path note.

5. The custom task should be invoked after Core Label target. It is safe to use AfterCompile target

6. The UpdateWorkItem flag can be used to enable or disable the task from updating the work items.

7. If the last label is empty, then the task will show bad performance because it will query for all the change sets.

8. Work item can be associated with multiple change sets, we will not display duplicates.

9. We will display the sorted list of change sets and work items.

10. AssemblyPath property should point to the folder containing Microsoft.TeamFoundation.Build.Tasks.VersionControl.dll.

Tested Scenarios

1. Multiple projects of different types with multiple configuration with

a. Area path not specified – got everything

b. Area path with recursive false, update flag false – got cs and wi belonging to specified node.

c. Area path with recursive false, update flag true – got cs and wi. Additionally updated wi belonging to specified node.

d. Area path with recursive true, update flag false – got all cs and wi.

e. Area path with recursive true, update flag true – got all cs and wi. Additionally updated all wi belonging to specified node.

2. Building project for the first time – working as expected

Source Code

[Download - sources]