问题
We are working with Team Foundation Server (Visual Studio 2010).
How can I get writer of the specific code block programmatically?
回答1:
With TFS API, you may be able to get to that data. Each changeset has a commiter. I would take the code offered up here. From this, you can add:
foreach (var change in cs.Changes)
{
if (change.Item.ServerItem != serverItem)
{
return;
}
//Get commiter
cs.Committer
While this doesn't get you 100% of the way there, it is at least a starting point.
回答2:
Fairly 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 i misunderstood your question. What you are looking for is to be able to get a changesetId based on a specific file path in TFS and then being able to see the modified items for that changeset and then being able to see the modification in the source code and know who the author of that source change is. Right?
If that's correct, can you not 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 you how to get changesets programmatically from TFS
- Now that you have the changeset you can retrive the changed file.
- In the example above, i am getting the details of the merge from that changeset. In your case you will have to use GetItems(String, VersionSpec, RecursionType, DeletedState, ItemType, Boolean)
- The changeset object has a property 'Owner' this will tell u who the author of the change is.
- Now if you want to select the details of the first changeset in that list, You will have to access Item.VersionControlServer see the details here http://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.item.versioncontrolserver.aspx
Does this help, can i provide additional details?
HTH.
Cheers, Tarun
回答3:
MSDN has Annotate option for the tracking of such information, but the default is on file-level and check-in operations. For such info, we usually use code comments, it may be not so professional but it is good.
来源:https://stackoverflow.com/questions/6507266/how-can-i-determine-the-author-of-a-block-of-code-programmatically-in-tfs