How to get changesets/workitems belonging to a particular sub folder (only)?

  1. Edit the tfsbuild.proj and over ride the label task definition. Do note that changes in Name and Files argument. The Files attribute is used to define the scope of labels incase it is disjoint. Name of the label now contains the explicit scope.
  2. Initialize the value of the property GetGhangesetForFolder. The folder should not be team project. For example (1) if your folder is $/teamproject/myfolder, then the value should be "myfolder", (2) if your folder is $/teamproject/myfoldder/component1 then the calue should be "myfolder/component1". 

Add the following stuff to your tfsbuild.proj

<PropertyGroup>  

<GetChangesetForFolder>_Component1_</GetChangesetForFolder>

</PropertyGroup>

<Target Name="CoreLabel"

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

          DependsOnTargets="$(CoreLabelDependsOn)" >

    <!-- Label all the latest non deleted files in workspace -->

    <Label

       Condition=" '$(SkipLabel)'!='true' "

       Workspace="$(WorkspaceName)"

       Name="$(BuildNumber)@$/$(TeamProject)/$(GetChangesetForFolder)"

       Version="W$(WorkspaceName)"

       Files="$/$(TeamProject)/$(GetChangesetForFolder)"

       Child="$(ChildLabel)"

       Comments="$(LabelTaskComment)"

       Recursive="$(RecursiveLabel)" />

 </Target>

Additionally note that you do not need to override the LabelQueryScope property.