Partilhar via


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]

Comments

  • Anonymous
    April 10, 2006
    The TeamPlain Team System blog links to a MSDN Virtual Lab: Managing Work Items with TeamPlain Web Access....

  • Anonymous
    January 22, 2007
    Hello! I am Billy Johnson Nice design. Enjoy! Good site! OK. 0n79p7k .

  • Anonymous
    February 10, 2007
    [url=http://avena-lee.freesitesworld.com/index.html] avena lee [/url]

  • Anonymous
    February 11, 2007
    Hi all , very nice site! Thank You !

  • Anonymous
    March 20, 2007
    Hi, Can you explain how to change code according to build type i.e. for ex. if the build type is Development do something else do something else in vsts2005. Something like #If DEVELOPMENT Then Response.Write("debug!") #Else Response.Write("release!") #End If End Sub

  • Anonymous
    March 20, 2007
    Correction : Hi, Can you explain how to change code according to build type i.e. for ex. if the build type is Development do something..., else, do something else... in vsts2005. Something like #If DEVELOPMENT Then Response.Write("development!") #Else Response.Write("sumthing else!") #End If End Sub

  • Anonymous
    July 02, 2007
    I've read about how to customize the scope of a Team Build, but the changesets and work item lists  generated are for changes that occurred between the current label and the last successful build label.  I need to be able to generate a list of changsets/work items between the current label and a previous build labe that I wish to select. The reason for this is that even if a build compiles successfully, it may not pass testing/QA and is therefore not considered a successful build.   I need to generate a list of changesets/work items between the current build label and the last build that successfully passes functional testing.  Is there a way to override the last successful build number in order to generate the list of changsets/work items that I want?

  • Anonymous
    March 28, 2008
    PingBack from http://employmentwagesblog.info/manish-agarwal-custom-msbuild-task-to-get-changesets-and-workitems/

  • Anonymous
    January 23, 2009
    Hi, Can you please put an updated link to the binaries/source please as gotdotnet is no longer active. Would be much appreciated. Thanks for the article and work, just what I am looking for. Cheers, Jon

  • Anonymous
    June 16, 2009
    PingBack from http://workfromhomecareer.info/story.php?id=28215