How to use TfsTeamProjectCollection in TFS

Viewed 567

I am trying to get an email address from an IdentityRef.

IdentityRef test = (IdentityRef)workItem.Fields["System.CreatedBy"];
var test2 = test.UniqueName;
var tfs = new TfsTeamProjectCollection(uri, credentials);
tfs.GetService<IIdentityManagementService2>();
var test3 = identityService.ReadIdentity(test2);

This code gives me "CS0246 The type or namespace name 'TfsTeamProjectCollection' could not be found (are you missing a using directive or an assembly reference?)"

I have tried a variety of "using" directives to get TfsTeamProjectCollection to recognize:

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.VersionControl.Client;
using assembly Microsoft.TeamFoundation.Client;
using namespace Microsoft.TeamFoundation.Client;

All of these give me some combination of "IDE0005: Using directive is unnecessary", "CS0234: The type or namespace name 'Foo' does not exist in the namespace 'Bar'", "CS0103: The name 'Foo' does not exist in the current context".

I have Microsoft.TeamFoundationServer.Client, Microsoft.TeamFoundationServer.ExtendedClient, Microsoft.VisualStudio.Services.Client, Microsoft.VisualStudio.Services.InteractiveClient installed

2 Answers

I was Facing the same issue. Even though installed the package of Microsoft.Teamfoundation.Client dll's for the same wasn't there in bin folder.

So make sure dll of Microsoft.Teamfoundation.Client is there in bin folder if not try to paste the dll of Microsoft.Teamfoundation.Client there.

Make sure you TFS Uri and Credentials are correct.

You are using an old version of libraires & packages that are no longer supported.

If you are using a before 2015 TFS or above, you need to update the relevant package as latest.

Below 2015 TFS version follow the below steps:

Install packages with latest versions and check steps here

Refer TFS 2015 above check here Link 1 & Link 2

Related