Writing code to find a Shelveset associated with a CodeReview Request work item
Asked Answered
B

0

8

I am new to C# (coming from Java) and am trying to write a report that counts the number of code reviews done.

I have no trouble iterating through the code review requests. When a code review is associated with a changeset, I use the following code which works fine:

Changeset changeset = versionControlServer.GetChangeSet(int.Parse(
    workItem.Fields["Associated Context"].Value.ToString()), true, true);

I am trying to do the equivalent with Shelvesets.

I am able to iterate through all the Shelvesets using the following code:

foreach (Shelveset shelveset in versionControlServer.QueryShelvesets(null,null) {
    Console.WriteLine(shelveset.Name);
}

Unfortunately, when I try to do the same command based on the name previously printed out, I get nothing returned. The following code returns an empty list.

foreach (Shelveset shelveset in versionControlServer.QueryShelvesets("ShelvesetName",null)) 
{
    Console.WriteLine(shelveset.Name);
}

Could someone help me to understand what I need to change so that versionControlServer.QueryShelvesets("ShelvesetName",null) returns the shelveset with the name that matches the Associated Context of the CodeReviewRequest work item?

Boon answered 28/3, 2017 at 2:11 Comment(9)
Your code is correct and I have tested that. Make sure the "ShelvesetName" is correct. Open that code review workitem and check if the name is wrong. If possible, please post the complete code snip here for future testing.Muldon
Thanks very much! Your confirmation really helps. I will checkBoon
The issue turned out to be that the owner is null. Once I changed this to a string such as "NW\\LFreeman", the call worked for me.Boon
Interestingly, if both owner and name are null, I get all Shelvesets. It only returns empty if name is not null but owner is.Boon
Which version of TFS you use and which of the TFS API version you use, 12.0 or 14.0?Muldon
Tfs 2012. We have not yet upgraded to a later version.Boon
It seems that you solved your issue in this case: #43083938Muldon
Yes, I'll update the other question with the solution.Boon
If you solved your issue, please add the reply for this issue.Muldon

© 2022 - 2024 — McMap. All rights reserved.