Zack Sloan
Zack Sloan

Reputation: 101

Unable to find type [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]

I am trying to put a build together on TFS that starts another build within a different TFS collection by using a PowerShell script that a coworker wrote and had working previously. However, this script was written and tested on VS 2015 Professional and I am using 2017 Enterprise. When I go to run this script in my build I get the following error:

Unable to find type [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]

when it hits this:

$tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer($serverName)

I have looked through the .dlls in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer but cannot find this dll (maybe specific to Professional 2015?)

How would I go about solving this issue? From my research it seems like I need to add the dll to the GAC, but not sure which dll to add. If this dll is not associated with Enterprise 2017, how would I change this line to work with my version?

Upvotes: 2

Views: 2622

Answers (4)

Kosmich
Kosmich

Reputation: 11

Only VS 2015 assemblies helped me in the same case... Order of adding is also very important!

    try
{

    $visualStudiopath = 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer'

    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.ControlsCore.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.ProjectManagement.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Common.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.VersionControl.Client.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Common.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Controls.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Client.dll"
    Add-type -path "$visualStudiopath\Microsoft.TeamFoundation.ProjectManagement.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Build.Common.dll"
}
catch [System.Reflection.ReflectionTypeLoadException]
{
   Write-Host "Message: $($_.Exception.Message)"
   Write-Host "StackTrace: $($_.Exception.StackTrace)"
   Write-Host "LoaderExceptions: $($_.Exception.LoaderExceptions)"
}

Upvotes: 0

Sam
Sam

Reputation: 559

See if this script helps. No binaries needed with this approach.

You can customize this per your requirements.

P.S. It works for TFS 2017.1

Upvotes: 0

Andy Li-MSFT
Andy Li-MSFT

Reputation: 30362

The object model client libraries are not in GAC.

Add the dll to load by Add-Type cmdlet like below: (In your scenario you need to add Microsoft.TeamFoundation.Client.dll)

$visualStudiopath = 'C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer'
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.VersionControl.Client.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Common.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Client.dll"
    Add-type -path "$visualStudiopath\Microsoft.TeamFoundation.ProjectManagement.dll"
    Add-Type -Path "$visualStudiopath\Microsoft.TeamFoundation.Build.Common.dll"

Upvotes: 4

Daniel Mann
Daniel Mann

Reputation: 58980

Install the NuGet package Microsoft.TeamFoundationServer.ExtendedClient.

Upvotes: 2

Related Questions