Agenda <ul><li>Introduction </li></ul><ul><ul><li>What? </li></ul></ul><ul><ul><li>Why? </li></ul></ul><ul><ul><li>Alterna...
Introduction – What? <ul><li>Allows you to control nearly all aspects of TFS programmatically. </li></ul><ul><ul><li>Build...
Introduction – Why? <ul><li>Process (or Methodology) Automation </li></ul><ul><li>Utilities </li></ul><ul><li>Application ...
Introduction – Alternatives? <ul><li>tf.exe and tfpt.exe </li></ul><ul><li>Third-Party Utilities and Products </li></ul><u...
Connecting <ul><li>Connect via: </li></ul><ul><ul><li>URL (e.g. http://tfsrtm:8080/) </li></ul></ul><ul><ul><li>Registered...
Connecting – Authentication <ul><li>Authentication does not occur immediately. </li></ul><ul><li>TeamFoundationServer.Auth...
Connecting – Authentication Process <ul><li>Integrated authentication will be attempted first. </li></ul><ul><li>If this f...
Connecting – Registered Servers <ul><li>The list of registered servers is stored in the registry (HKCUSoftwareMicrosoftVis...
Connecting – Demo
Services <ul><li>Each TFS subsystem provides its own API. </li></ul><ul><li>To access these you need to: </li></ul><ul><ul...
Services <ul><li>Build </li></ul><ul><ul><li>Microsoft.TeamFoundation.Build.Common.dll </li></ul></ul><ul><ul><li>BuildCon...
Services – Demo
Web Services <ul><li>TFS is based around a number of web services. </li></ul><ul><li>The APIs are a strongly-typed wrapper...
Web Services – Demo
Scenarios <ul><li>Builds </li></ul><ul><ul><li>Starting Builds </li></ul></ul><ul><ul><li>Build History </li></ul></ul><ul...
Builds – Starting Builds <ul><li>Why? </li></ul><ul><ul><li>Work around TFS limitations </li></ul></ul><ul><ul><li>Impleme...
Builds – Build History <ul><li>Why? </li></ul><ul><ul><li>Provide improved build status notification </li></ul></ul><ul><u...
Common Structure – Areas and Iterations <ul><li>Why? </li></ul><ul><ul><li>Integrate with project planning tools </li></ul...
Common Structure – Iterating Team Projects <ul><li>Why? </li></ul><ul><ul><li>Performing operations/maintenance across all...
Source Control – Workspaces <ul><li>Why? </li></ul><ul><ul><li>Nearly all source control operations require a workspace. <...
Source Control – Download File <ul><li>Why? </li></ul><ul><ul><li>Lots of reasons... </li></ul></ul><ul><li>How? </li></ul...
Source Control – Get, Check-Out, Check-In <ul><li>Why? </li></ul><ul><ul><li>Lots of reasons </li></ul></ul><ul><li>How? <...
Work Items – Creating <ul><li>Why? </li></ul><ul><ul><li>Batch creation </li></ul></ul><ul><ul><li>Migration and synchroni...
Work Items – Running WIQL <ul><li>Why? </li></ul><ul><ul><li>Exporting work items </li></ul></ul><ul><ul><li>Complicated r...
 
Upcoming SlideShare
Loading in...5
×

Getting Started With The TFS API

19,465
-1

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
19,465
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
201
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Getting Started With The TFS API

  1. 2. Agenda <ul><li>Introduction </li></ul><ul><ul><li>What? </li></ul></ul><ul><ul><li>Why? </li></ul></ul><ul><ul><li>Alternatives? </li></ul></ul><ul><li>Building Blocks </li></ul><ul><ul><li>Connecting </li></ul></ul><ul><ul><li>Services </li></ul></ul><ul><ul><li>Web Services </li></ul></ul><ul><li>Scenarios </li></ul>
  2. 3. Introduction – What? <ul><li>Allows you to control nearly all aspects of TFS programmatically. </li></ul><ul><ul><li>Builds </li></ul></ul><ul><ul><li>Common Structure </li></ul></ul><ul><ul><li>Source Control </li></ul></ul><ul><ul><li>Work Items </li></ul></ul><ul><li>Mostly exposed via .NET assemblies. Some functionality is only available via web services. </li></ul><ul><li>Assemblies available by installing the Visual Studio SDK. </li></ul>
  3. 4. Introduction – Why? <ul><li>Process (or Methodology) Automation </li></ul><ul><li>Utilities </li></ul><ul><li>Application Integration </li></ul><ul><li>Advanced Build Scenarios </li></ul>
  4. 5. Introduction – Alternatives? <ul><li>tf.exe and tfpt.exe </li></ul><ul><li>Third-Party Utilities and Products </li></ul><ul><li>PowerShell </li></ul><ul><ul><li>Still requires knowledge of the APIs. </li></ul></ul>
  5. 6. Connecting <ul><li>Connect via: </li></ul><ul><ul><li>URL (e.g. http://tfsrtm:8080/) </li></ul></ul><ul><ul><li>Registered Server Name (e.g. TFSRTM) </li></ul></ul><ul><li>Two methods: </li></ul><ul><ul><li>New TeamFoundationServer(url) </li></ul></ul><ul><ul><li>TeamFoundationServerFactory.GetServer(url) </li></ul></ul><ul><ul><ul><li>Returns a cached server if a server with the same URL or registered server name has already been accessed. </li></ul></ul></ul>
  6. 7. Connecting – Authentication <ul><li>Authentication does not occur immediately. </li></ul><ul><li>TeamFoundationServer.Authenticate() will force authentication to occur. </li></ul><ul><li>TeamFoundationServer.EnsureAuthenticated() will authenticate if necessary. </li></ul><ul><li>Most TFS APIs will call EnsureAuthenticated(). </li></ul>
  7. 8. Connecting – Authentication Process <ul><li>Integrated authentication will be attempted first. </li></ul><ul><li>If this fails then a TeamFoundationServerUnauthorizedException will be thrown. </li></ul><ul><li>Both methods of connecting support passing a fallback credentials provider which will be called if integrated authentication fails. </li></ul><ul><li>TFS includes a UICredentialsProvider out-of-the-box which will prompt the user for credentials. </li></ul>
  8. 9. Connecting – Registered Servers <ul><li>The list of registered servers is stored in the registry (HKCUSoftwareMicrosoftVisualStudio8.0TeamFoundationServers). </li></ul><ul><li>Accessed programmatically by calling RegisteredServers.GetServers(). </li></ul><ul><li>Caveat: You cannot use a fallback credentials provider. </li></ul><ul><li>Workaround: Pass the registered server name to one of the connection methods that takes a fallback credentials provider. </li></ul>
  9. 10. Connecting – Demo
  10. 11. Services <ul><li>Each TFS subsystem provides its own API. </li></ul><ul><li>To access these you need to: </li></ul><ul><ul><li>Add the necessary references. </li></ul></ul><ul><ul><li>Pass the API’s entry point to the TeamFoundationServer.GetService() method. </li></ul></ul><ul><li>For example, to access the Work Item API: </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.WorkItemTracking.Client.dll. </li></ul></ul><ul><ul><li>Dim workItemStore As WorkItemStore = DirectCast(server.GetService(GetType(WorkItemStore)), WorkItemStore) </li></ul></ul>
  11. 12. Services <ul><li>Build </li></ul><ul><ul><li>Microsoft.TeamFoundation.Build.Common.dll </li></ul></ul><ul><ul><li>BuildController or BuildStore </li></ul></ul><ul><li>Common Structure </li></ul><ul><ul><li>Microsoft.TeamFoundation.dll </li></ul></ul><ul><ul><li>ICommonStructureService </li></ul></ul><ul><li>Eventing </li></ul><ul><ul><li>Microsoft.TeamFoundation.dll </li></ul></ul><ul><ul><li>IEventService </li></ul></ul><ul><li>Version Control </li></ul><ul><ul><li>Microsoft.TeamFoundation.VersionControl.Client.dll </li></ul></ul><ul><ul><li>VersionControlServer </li></ul></ul><ul><li>Work Item Tracking </li></ul><ul><ul><li>Microsoft.TeamFoundation.WorkItemTracking.Client.dll </li></ul></ul><ul><ul><li>WorkItemStore </li></ul></ul>
  12. 13. Services – Demo
  13. 14. Web Services <ul><li>TFS is based around a number of web services. </li></ul><ul><li>The APIs are a strongly-typed wrapper for these web services. </li></ul><ul><li>Some functionality is not available in the API and you must call the web services directly. </li></ul><ul><li>Physically the web services are stored in: </li></ul><ul><ul><li>%ProgramFiles%Microsoft Visual Studio 2005 Team Foundation ServerWeb Services<Subsystem>v1.0<ServiceName>.asmx </li></ul></ul><ul><li>Virtually the web services are available at: </li></ul><ul><ul><li>http://tfsrtm:8080/<Subsystem>/v1.0/<ServiceName>.asmx </li></ul></ul><ul><li>Proxies are already available for some of the assemblies in the .Proxy namespace of the relevant subsystem. </li></ul><ul><li>Always use APIs in preference to calling web services directly! </li></ul>
  14. 15. Web Services – Demo
  15. 16. Scenarios <ul><li>Builds </li></ul><ul><ul><li>Starting Builds </li></ul></ul><ul><ul><li>Build History </li></ul></ul><ul><li>Common Structure </li></ul><ul><ul><li>Creating Areas and Iterations </li></ul></ul><ul><ul><li>Iterating Team Projects </li></ul></ul><ul><li>Source Control </li></ul><ul><ul><li>Working with Workspaces </li></ul></ul><ul><ul><li>Getting Items from Source Control </li></ul></ul><ul><ul><li>Get, Check-Out and Check-In </li></ul></ul><ul><li>Work Items </li></ul><ul><ul><li>Creating Work Items </li></ul></ul><ul><ul><li>Running WIQL </li></ul></ul>
  16. 17. Builds – Starting Builds <ul><li>Why? </li></ul><ul><ul><li>Work around TFS limitations </li></ul></ul><ul><ul><li>Implementing CI </li></ul></ul><ul><ul><li>Integrating builds into other processes </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.Build.Common.dll </li></ul></ul><ul><ul><li>Populate an instance of BuildParameters with the build settings </li></ul></ul><ul><ul><ul><li>The TeamFoundationServer must use a URL </li></ul></ul></ul><ul><ul><li>Retrieve the BuildController service </li></ul></ul><ul><ul><li>Call StartBuild on the BuildController and pass it the BuildParameters </li></ul></ul>
  17. 18. Builds – Build History <ul><li>Why? </li></ul><ul><ul><li>Provide improved build status notification </li></ul></ul><ul><ul><li>Clean up old builds </li></ul></ul><ul><ul><li>Locate and use build outputs </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.Build.Common.dll </li></ul></ul><ul><ul><li>Retrieve the BuildStore service </li></ul></ul><ul><ul><li>Call GetListOfBuilds </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>Builds in chronological order </li></ul></ul><ul><ul><li>Build data is an abstract, call GetBuildDetails for the details </li></ul></ul>
  18. 19. Common Structure – Areas and Iterations <ul><li>Why? </li></ul><ul><ul><li>Integrate with project planning tools </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.dll </li></ul></ul><ul><ul><li>Retrieve the ICommonStructureService service </li></ul></ul><ul><ul><li>Use the GetNodeFromPath and CreateNode methods </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>Areas and iterations are stored in a single hierarchy </li></ul></ul><ul><ul><li>Referenced via URIs not paths, but paths can be mapped back to a node </li></ul></ul>
  19. 20. Common Structure – Iterating Team Projects <ul><li>Why? </li></ul><ul><ul><li>Performing operations/maintenance across all team projects </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.dll </li></ul></ul><ul><ul><li>Retrieve the ICommonStructureService service </li></ul></ul><ul><ul><li>Use the ListProjects method </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>The ListProjects method only returns well-formed projects, ListAllProjects will return all projects regardless of status. </li></ul></ul>
  20. 21. Source Control – Workspaces <ul><li>Why? </li></ul><ul><ul><li>Nearly all source control operations require a workspace. </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.VersionControl.Client.dll </li></ul></ul><ul><ul><li>Retrieve the VersionControlServer service </li></ul></ul><ul><ul><li>Use CreateWorkspace/GetWorkspace </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>You can get a workspace based on a local path </li></ul></ul>
  21. 22. Source Control – Download File <ul><li>Why? </li></ul><ul><ul><li>Lots of reasons... </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.VersionControl.Client.dll </li></ul></ul><ul><ul><li>Retrieve the VersionControlServer service </li></ul></ul><ul><ul><li>Use DownloadFile </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>Discuss VersionSpec </li></ul></ul><ul><ul><li>Contrast with Get </li></ul></ul>
  22. 23. Source Control – Get, Check-Out, Check-In <ul><li>Why? </li></ul><ul><ul><li>Lots of reasons </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.VersionControl.Client.dll </li></ul></ul><ul><ul><li>Retrieve the VersionControlServer service </li></ul></ul><ul><ul><li>Retrieve the appropriate workspace </li></ul></ul><ul><ul><li>Use Get, PendAdd, PendDelete, PendEdit, CheckIn </li></ul></ul>
  23. 24. Work Items – Creating <ul><li>Why? </li></ul><ul><ul><li>Batch creation </li></ul></ul><ul><ul><li>Migration and synchronisation </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.WorkItemTracking.Client.dll </li></ul></ul><ul><ul><li>Retrieve the WorkItemStore service </li></ul></ul><ul><ul><li>Navigate through Projects and WorkItemTypes </li></ul></ul><ul><ul><li>Call NewWorkItem </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>Migration and synchronisation toolkit </li></ul></ul>
  24. 25. Work Items – Running WIQL <ul><li>Why? </li></ul><ul><ul><li>Exporting work items </li></ul></ul><ul><ul><li>Complicated reporting </li></ul></ul><ul><ul><li>Migration and synchronisation </li></ul></ul><ul><li>How? </li></ul><ul><ul><li>Add a reference to Microsoft.TeamFoundation.WorkItemTracking.Client.dll </li></ul></ul><ul><ul><li>Retrieve the WorkItemStore service </li></ul></ul><ul><ul><li>Call Query or QueryCount </li></ul></ul><ul><li>Notes </li></ul><ul><ul><li>Stored queries </li></ul></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×