I've written a service that grabs all changesets in all collections on my TFS.
I can dynamically get the collection name of any changeset from the changeset object but I'm having trouble trying to find the team project name that the changeset exists in.
Can I somehow find the team project name a changeset belongs to?
foreach (Changeset cs in allChangeSets)
{
if (cs.Comment != null && ChangeSetFinderMVC.Utils.TFSUtil.Contains(cs.Comment, id))
{
var cso = new ChangeSetObj();
cso.ChangesetId = cs.ChangesetId;
cso.CheckinNote = cs.CheckinNote;
cso.Comment = cs.Comment;
cso.Committer = cs.Committer;
cso.CommitterDisplayName = cs.CommitterDisplayName;
cso.Collection = cs.VersionControlServer.TeamProjectCollection.Name;
cso.TeamProject = "????";
changeSetList.Add(cso);
}
}
Since a changeset may apply to multiple projects at once, you will need to look at each item that changed in the changeset and see what project it was associated with.
Inside the Changeset
, you can access the TFS path of each changed item and see its server path.
foreach (Changeset changeSet in changeSets)
{
foreach (Change change in changeSet.Changes)
{
string tfsDir = change.Item.ServerItem;
// Example: "$/ProjectName/SomeFolders/SomeFile.cs"
// More logic to handle this string goes here.
}
}
If you need some regex to find the project name, try this: ^\$\/(?<Project>.+?)\/
Make sure you access the 'Project' group in the regex match.