How can I find all of the labels for a particular TFS project sub-folder?

Go To StackoverFlow.com

17

Assume there is a TFS project Project with the subfolders trunk and 1.0. trunk contains the latest version of the application code for this project and 1.0 contains the code for the same application for the released version of the same name.

There are labels for both sub-folders and all of the labels include files in only one of the sub-folders. [You could also assume that the labels are recursive on a specific (maximum) changeset for all of the files in the entire sub-folder too if that simplifies your answer.]

How can I create a list of labels for one of these sub-folders, using Visual Studio, the TFS tf.exe command line tool, or any other tool or code that is publicly (and freely) available.

Note – I've written T-SQL code that queries the TFS version control database directly to generate this info, but I'm curious whether there are 'better' ways to do so.

2012-04-04 18:11
by Kenny Evitt


33

In Visual Studio, in the Source Control Explorer window, right-click the sub-folder for which you want to list the relevant labels and pick View History from the context menu. In the History window that should appear, there should be a sub-tab Labels (as highlighted below) that lists labels applied to that sub-folder (but not specific items in that sub-folder).

enter image description here

2012-04-04 18:26
by Kenny Evitt
Hi , this is showing the labels only created for my workspsace (by me ), how can i see the other labels created by other users ?. - ansar 2015-10-07 06:47
@ansar I'm not using TFS currently so I can't check, but I don't remember this being restricted by workspace in the version of TFS I was using; I certainly wasn't creating the labels I found - Kenny Evitt 2015-10-07 11:17
@ansar What about tinman's answer - Kenny Evitt 2015-10-07 11:18
Sorry my mistake , there were some labels applied for files where they have to be applied on folder , I have applied the lables at folder that is why was able to see the lables which i have created and could not be able to see the others Issue is resolved by my TFS admin . Thank you for your response and sorry agai - ansar 2015-10-08 12:49


2

To find labels in Visual Studio

  1. Open Source Control Explorer.

  2. In Source Control Explorer, open the shortcut menu for the collection, team project, branch, folder, or file that you are looking for.

  3. Select View History. You will see a new window with all the Changesets.

  4. Select Labels in the tab menu as highlighted in the below image.

enter image description here

2015-02-04 18:35
by Sundeep
Note that if you have labelled branches within a folder, those labels won't show up this way for the parent folder. You have to do View History on each branch unfortunately - AaronLS 2017-07-03 14:23


2

I needed to do this on the command line today so here is a batch file that hopefully does the same thing (we've only just started using TFS and have limited labels on folders to test the OP's requirements).

You'll need to edit the collection parameter to tf to whatever your setup is, and possibly provide the login details depending on how your authentication is done.

@ECHO OFF
SETLOCAL EnableDelayedExpansion

@REM Check required parameters
IF [%1]==[] GOTO :usage

tf labels /owner:* /format:detailed %2 /collection:http://server:8080/tfs/collection > labels.txt 2> nul

SET CURRENT_LABEL=
FOR /F "tokens=1,2,3" %%G IN (labels.txt) DO (
    IF [%%G]==[Label] (
        SET CURRENT_LABEL=%%I
    ) ELSE (
        IF /I [%%H]==[%1] (
            ECHO !CURRENT_LABEL!
        )
    )
)
DEL labels.txt

GOTO :eof
@REM Subroutines

:usage
echo tfs_labelsforfolder - Display all labels that are applied to a folder.
echo.
echo tfs_labelsforfolder ^<folder^> ^[label_filter^]
echo.
echo     folder       - The folder to show the labels for, e.g. $/Project/folder
echo     label_filter - Search pattern to use in tf labels command.
echo.
GOTO :eof
2015-10-01 15:21
by tinman
Ads