Home > ALM, TFS, TFS2012 > TFS 2012 API: Find all Solutions in Source Control

TFS 2012 API: Find all Solutions in Source Control

In this article, I am going to show how you can retrieve source control to find all solutions. Actually the solution I am provide can find any specific file or pattern. The code supports wildcard search. I AM NOT DOING ANY VALIDATION TO KEEP THE CODE SHORT. If more than one match found, my code will comma separate them. We will use this code in a later post to incorporate it in a Team Build Definition to build all solutions in the Source Control.

Start by Create a WPF Application

Add the following references:




Build the following UI but replace the values in the textboxes with your team project Url and file pattern respectively:


The following code is in the code behind

private void Button_Click_1(object sender, RoutedEventArgs e)
//Get Team Project collection form Uri
var teamProjectCollection = GetTeamProjectCollection(new Uri(TeamProjectCollectionTextBox.Text));

//Get version control instance from team project collection
var versionControlServer = GetVersionControlServer(teamProjectCollection);

//Get server path for all files with pattern
var pathList = GetPathList(PatternTextBox.Text, versionControlServer);

//Comma separate results
ResultTextBox.Text = string.Join(",", pathList);


private IEnumerable<string> GetPathList(string pattern,
VersionControlServer versionControlServer)
List<string> solutionList = new List<string>();

//Get items with pattern (must be prefixed with root path (server or local))
// for example $/ or C:\sc
//Version sepc = latest code
// recursionType = Full =  search sub folders
// DeletedState =  only non-deleted files
//ItemType = files
var lists = versionControlServer.GetItems(pattern,

if (lists.Items.Any())
var list = lists.Items
.Select(i => i.ServerItem)

return solutionList; ;

private VersionControlServer GetVersionControlServer(TfsTeamProjectCollection tfsTeamProjectcollection)
var versionControlServer = tfsTeamProjectcollection.GetService<VersionControlServer>();

return versionControlServer;

private TfsTeamProjectCollection GetTeamProjectCollection(Uri uri)
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(uri);

return tfs;


  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: