How can I identify the author of a block of code programmatically in TFS?

We work with Team Foundation Server (Visual Studio 2010).

How can I programmatically create a script for a specific code?

+2
source share
3 answers

Using the TFS API you can get this data. Each change set has a committer. I would suggest the code here . From this you can add:

foreach (var change in cs.Changes) { if (change.Item.ServerItem != serverItem) { return; } //Get commiter cs.Committer 

As long as this does not give you 100% of the way, this is at least a starting point.

0
source

Pretty simple.

I have a working demo on my blog => http://geekswithblogs.net/TarunArora/archive/2011/06/26/tfs-2010-sdk-smart-merge-programmatically-create-your-own-merge.aspx

Edited

I am very sorry that I did not understand your question. What you are looking for is the ability to get changeetId based on a specific file path in TFS, and then be able to see the changed elements for this set of changes, and then be able to see the changes in the source code and know who the author is from this source change . Right?

If this is correct, can you do the following?

 public static void GetMergeDetailsForChangeSet() { var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("Enter the url of team project")); var versionControl = tfs.GetService<VersionControlServer>(); var a = versionControl.GetChangeset(12322); VersionSpec changeSpec = new ChangesetVersionSpec(a.Changes[0].Item.ChangesetId); var changeSetDetails = a.Changes[0].Item.VersionControlServer.QueryMergesWithDetails( null, null, 0, a.Changes[0].Item.ServerItem, changeSpec, a.Changes[0].Item.DeletionId, changeSpec, changeSpec, RecursionType.Full); } 
  • My blog post shows how to get software changes from TFS
  • Now that you have a set of changes, you can restore the modified file.
  • In the above example, I get merge details with this set of changes. In your case you will have to use GetItems (String, VersionSpec, RecursionType, DeletedState, ItemType, Boolean)
  • The changeet object has the "Owner" property, this will tell who the author of the change is.
  • Now, if you want to select the details of the first set of changes in this list, you will need to access Item.VersionControlServer to see the details here http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol. client.item.versioncontrolserver.aspx

Does this help, can I provide more information?

NTN.

Cheers, Tarun

-1
source

MSDN has Annotate to track this information, but by default, file and registration operations are used. For such information, we usually use code comments, it may not be so professional, but it’s good.

-2
source

All Articles