I'm trying to have my C# application go through all of the TFS git projects and search through the files for a string pattern. I start out with my connection this way.
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://tfs.domain.com/tfs"));
tfs.EnsureAuthenticated();
var gitSvc = tfs.GetService<GitRepositoryService>();
I'm not seeing a way to get all the git projects information to put it through a foreach loop. I saw some code from here that will get all projects from tfs.Getservice.
var tfs = TfsTeamProjectCollectionFactory
.GetTeamProjectCollection(new Uri("http://{tfsserver}:8080/tfs"));
tfs.EnsureAuthenticated();
var versionControl = tfs.GetService<VersionControlServer>();
StreamWriter outputFile = new StreamWriter(@"C:\Find.txt");
var allProjs = versionControl.GetAllTeamProjects(true);
foreach (var teamProj in allProjs)
{
foreach (var filePattern in filePatterns)
{
var items = versionControl.GetItems(teamProj.ServerItem + "/" + filePattern, RecursionType.Full).Items
.Where(i => !i.ServerItem.Contains("_ReSharper")); //skipping resharper stuff
foreach (var item in items)
{
List<string> lines = SearchInFile(item);
if (lines.Count > 0)
{
outputFile.WriteLine("FILE:" + item.ServerItem);
outputFile.WriteLine(lines.Count.ToString() + " occurence(s) found.");
outputFile.WriteLine();
}
foreach (string line in lines)
{
outputFile.WriteLine(line);
}
if (lines.Count > 0)
{
outputFile.WriteLine();
}
}
}
outputFile.Flush();
}
}
How can I do something similar like the code above, but by using Team Foundations Git library?