0

I have an Area that I've created using the SDK, and I have a Team. How can I, using the SDK, add that Area to the Team?

It's simple enough to do so with an Iteration, using the WorkHttpClient.PostTeamIterationAsync() method (code below), but there's no corresponding method available to do the same with an Area.

I looked briefly at the method's source code, but it contains a GUID indicating the target location (Iterations). If I can avoid it, I'd rather not risk getting down to that level by modifying it for my own use for Areas. Surely there's a higher-level way to do this.

According to this Q&A, it can be done via the REST API—but I'm using the SDK. Then there's this, but the answers there appear to be using an outdated version. The classes referenced aren't available in the latest stable version.

Can this be done?


Private Function AddSprintToTeam(Sprint As Classifications.Iteration) As TeamSettingsIteration
  Dim oContext As TeamContext
  Dim oSprint As TeamSettingsIteration
  Dim oTeams As List(Of WebApiTeam)
  Dim oTeam As WebApiTeam

  Using oTeamClient As TeamHttpClient = Utils.Connection.GetClient(Of TeamHttpClient)
    Using oWorkClient As WorkHttpClient = Utils.Connection.GetClient(Of WorkHttpClient)
      oTeams = oTeamClient.GetTeamsAsync(ProjectName).Result
      oTeam = oTeams.Single(Function(Team) Team.Name.StartsWith(ProjectName))

      oContext = New TeamContext(ProjectName, oTeam.Name)
      oSprint = New TeamSettingsIteration With {.Id = Sprint.Identifier}
      oSprint = oWorkClient.PostTeamIterationAsync(oSprint, oContext).Result
    End Using
  End Using

  Return oSprint
End Function
InteXX
  • 6,135
  • 6
  • 43
  • 80
  • I think you'll need the Extended Client nuget package to reference the classes from the older examples. They use the old Soap API instead of the REST API. https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/16.178.1-preview – jessehouwing Dec 28 '20 at 07:08
  • The guid you're looking for can be queried from the CommonStructureService if I remember correctly. Or by using the WorkItemStore which has a AreaPathNoder and an Iteration Nodes property. – jessehouwing Dec 28 '20 at 07:17
  • You can also query the classification nodes using the WorkItemTrackingHttpClient: https://learn.microsoft.com/en-us/dotnet/api/microsoft.teamfoundation.workitemtracking.webapi.workitemtrackinghttpclient you're looking for the `GetClassificationNodeAsync` function. – jessehouwing Dec 28 '20 at 07:35
  • Alas, I didn't have any luck with any of these. I couldn't find the `CommonStructureService` type nor the `AreaPathNode` or `IterationNode` properties on the `WorkItemStore` type, and the node returned by `GetClassificationNodeAsync()` doesn't include the `LocationId` as indicated in the source for `PostTeamIterationAsync()`. In the end, though, I was able to solve the problem using `UpdateTeamFieldValuesAsync()`. Thanks for giving it a shot. – InteXX Dec 29 '20 at 10:15
  • WorkItemStore is the new REST based work item client. The code samples use the old Soap client. Those require adding the TeamFoundation.Client.Extended nuget package. – jessehouwing Dec 29 '20 at 15:29
  • I'm still not following you. *"WorkItemStore is the new REST based work item client"* All indications I'm finding show this as the old client. I've added the package, yes, but I don't see either `WorkItemStore.AreaPathNode` or `WorkItemStore.IterationNode`. I found an `ICommonStructureService` interface—albeit with no apparent way to wire it up—but there doesn't seem to be any facility there for querying the location `GUID`. – InteXX Dec 29 '20 at 16:42
  • You can call the `GetService` method on the TfsTeamProjectCollection object to retrieve an instance of these interfaces. The Client Object Model will give you an instance to work with. You can use the structure service to walk through the object tree and some of the tree elements are iterations and areas. It's not the easiest interface to work with. – jessehouwing Dec 29 '20 at 19:44
  • And you an use the WorkItemStore's Projects property to get a reference to the project and from there dig into the Iteration Nodes https://learn.microsoft.com/en-us/previous-versions/visualstudio/visual-studio-2013/bb164776(v=vs.120) The Client Object Model isn't the best documented in the world. I rely mostly on dotPeek/ilSpy to find the types I'm interested in, then use the Find Usages option to find where and how to find it. – jessehouwing Dec 29 '20 at 19:50
  • 1
    Sounds like something akin to dropping a river rock on one's toe :-) OK, I'll give it a shot. – InteXX Dec 29 '20 at 23:05

1 Answers1

1

You can use UpdateTeamFieldValuesAsync() Method to add an existing Area to an existing Team. Check here.

See the related rest api here. You can check out the example given in the Rest api document.

Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • I'm almost ready to provide an update for your other question. In preparation for that, I'm [having trouble](https://stackoverflow.com/q/65486808) getting `UpdateTeamFieldValuesAsync()` to work. – InteXX Dec 29 '20 at 03:18
  • OK, `UpdateTeamFieldValuesAsync()` works. I've been able to add an Area to a Team. Thank you. – InteXX Dec 30 '20 at 00:39