getting started with the tfs api

26
www.TechnologyOneCorp.com [email protected] om William Bartholomew Domain Owner – Developer Productivity November 2007 Getting Started with the TFS API

Upload: wbarthol

Post on 13-May-2015

19.100 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Getting Started With The TFS API

www.TechnologyOneCorp.com

[email protected]

William BartholomewDomain Owner – Developer Productivity

November 2007

Getting Started with the TFS API

Page 2: Getting Started With The TFS API

Agenda

Introduction What? Why? Alternatives?

Building Blocks Connecting Services Web Services

Scenarios

Page 3: Getting Started With The TFS API

Introduction – What?

Allows you to control nearly all aspects of TFS programmatically. Builds Common Structure Source Control Work Items

Mostly exposed via .NET assemblies. Some functionality is only available via web services.

Assemblies available by installing the Visual Studio SDK.

Page 4: Getting Started With The TFS API

Introduction – Why?

Process (or Methodology) Automation

Utilities

Application Integration

Advanced Build Scenarios

Page 5: Getting Started With The TFS API

Introduction – Alternatives?

tf.exe and tfpt.exe

Third-Party Utilities and Products

PowerShell Still requires knowledge of the APIs.

Page 6: Getting Started With The TFS API

Connecting

Connect via: URL (e.g. http://tfsrtm:8080/) Registered Server Name (e.g. TFSRTM)

Two methods: New TeamFoundationServer(url) TeamFoundationServerFactory.GetServer(url)

• Returns a cached server if a server with the same URL or registered server name has already been accessed.

Page 7: Getting Started With The TFS API

Connecting – Authentication

Authentication does not occur immediately.

TeamFoundationServer.Authenticate() will force authentication to occur.

TeamFoundationServer.EnsureAuthenticated() will authenticate if necessary.

Most TFS APIs will call EnsureAuthenticated().

Page 8: Getting Started With The TFS API

Connecting – Authentication Process

Integrated authentication will be attempted first.

If this fails then a TeamFoundationServerUnauthorizedException will be thrown.

Both methods of connecting support passing a fallback credentials provider which will be called if integrated authentication fails.

TFS includes a UICredentialsProvider out-of-the-box which will prompt the user for credentials.

Page 9: Getting Started With The TFS API

Connecting – Registered Servers

The list of registered servers is stored in the registry (HKCU\Software\Microsoft\VisualStudio\8.0\TeamFoundation\Servers).

Accessed programmatically by calling RegisteredServers.GetServers().

Caveat: You cannot use a fallback credentials provider.

Workaround: Pass the registered server name to one of the connection methods that takes a fallback credentials provider.

Page 10: Getting Started With The TFS API

Connecting – Demo

Page 11: Getting Started With The TFS API

Services

Each TFS subsystem provides its own API.

To access these you need to: Add the necessary references. Pass the API’s entry point to the

TeamFoundationServer.GetService() method.

For example, to access the Work Item API: Add a reference to

Microsoft.TeamFoundation.WorkItemTracking.Client.dll. Dim workItemStore As WorkItemStore =

DirectCast(server.GetService(GetType(WorkItemStore)), WorkItemStore)

Page 12: Getting Started With The TFS API

Services

Build Microsoft.TeamFoundation.Build.Common.dll BuildController or BuildStore

Common Structure Microsoft.TeamFoundation.dll ICommonStructureService

Eventing Microsoft.TeamFoundation.dll IEventService

Version Control Microsoft.TeamFoundation.VersionControl.Client.dll VersionControlServer

Work Item Tracking Microsoft.TeamFoundation.WorkItemTracking.Client.dll WorkItemStore

Page 13: Getting Started With The TFS API

Services – Demo

Page 14: Getting Started With The TFS API

Web Services

TFS is based around a number of web services.

The APIs are a strongly-typed wrapper for these web services.

Some functionality is not available in the API and you must call the web services directly.

Physically the web services are stored in: %ProgramFiles%\Microsoft Visual Studio 2005 Team Foundation Server\

Web Services\<Subsystem>\v1.0\<ServiceName>.asmx

Virtually the web services are available at: http://tfsrtm:8080/<Subsystem>/v1.0/<ServiceName>.asmx

Proxies are already available for some of the assemblies in the .Proxy namespace of the relevant subsystem.

Always use APIs in preference to calling web services directly!

Page 15: Getting Started With The TFS API

Web Services – Demo

Page 16: Getting Started With The TFS API

Scenarios

Builds Starting Builds Build History

Common Structure Creating Areas and Iterations Iterating Team Projects

Source Control Working with Workspaces Getting Items from Source Control Get, Check-Out and Check-In

Work Items Creating Work Items Running WIQL

Page 17: Getting Started With The TFS API

Builds – Starting Builds

Why? Work around TFS limitations Implementing CI Integrating builds into other processes

How? Add a reference to Microsoft.TeamFoundation.Build.Common.dll Populate an instance of BuildParameters with the build settings

• The TeamFoundationServer must use a URL

Retrieve the BuildController service Call StartBuild on the BuildController and pass it the

BuildParameters

Page 18: Getting Started With The TFS API

Builds – Build History

Why? Provide improved build status notification Clean up old builds Locate and use build outputs

How? Add a reference to Microsoft.TeamFoundation.Build.Common.dll Retrieve the BuildStore service Call GetListOfBuilds

Notes Builds in chronological order Build data is an abstract, call GetBuildDetails for the details

Page 19: Getting Started With The TFS API

Common Structure – Areas and Iterations

Why? Integrate with project planning tools

How? Add a reference to Microsoft.TeamFoundation.dll Retrieve the ICommonStructureService service Use the GetNodeFromPath and CreateNode methods

Notes Areas and iterations are stored in a single hierarchy Referenced via URIs not paths, but paths can be mapped back

to a node

Page 20: Getting Started With The TFS API

Common Structure – Iterating Team Projects

Why? Performing operations/maintenance across all team projects

How? Add a reference to Microsoft.TeamFoundation.dll Retrieve the ICommonStructureService service Use the ListProjects method

Notes The ListProjects method only returns well-formed projects,

ListAllProjects will return all projects regardless of status.

Page 21: Getting Started With The TFS API

Source Control – Workspaces

Why? Nearly all source control operations require a workspace.

How? Add a reference to

Microsoft.TeamFoundation.VersionControl.Client.dll Retrieve the VersionControlServer service Use CreateWorkspace/GetWorkspace

Notes You can get a workspace based on a local path

Page 22: Getting Started With The TFS API

Source Control – Download File

Why? Lots of reasons...

How? Add a reference to

Microsoft.TeamFoundation.VersionControl.Client.dll Retrieve the VersionControlServer service Use DownloadFile

Notes Discuss VersionSpec Contrast with Get

Page 23: Getting Started With The TFS API

Source Control – Get, Check-Out, Check-In

Why? Lots of reasons

How? Add a reference to

Microsoft.TeamFoundation.VersionControl.Client.dll Retrieve the VersionControlServer service Retrieve the appropriate workspace Use Get, PendAdd, PendDelete, PendEdit, CheckIn

Page 24: Getting Started With The TFS API

Work Items – Creating

Why? Batch creation Migration and synchronisation

How? Add a reference to

Microsoft.TeamFoundation.WorkItemTracking.Client.dll Retrieve the WorkItemStore service Navigate through Projects and WorkItemTypes Call NewWorkItem

Notes Migration and synchronisation toolkit

Page 25: Getting Started With The TFS API

Work Items – Running WIQL

Why? Exporting work items Complicated reporting Migration and synchronisation

How? Add a reference to

Microsoft.TeamFoundation.WorkItemTracking.Client.dll Retrieve the WorkItemStore service Call Query or QueryCount

Notes Stored queries

Page 26: Getting Started With The TFS API

www.TechnologyOneCorp.com

[email protected]

William BartholomewDomain Owner – Developer Productivity

November 2007

Getting Started with the TFS API