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

爱⌒轻易说出口 提交于 2019-12-07 18:28:37

问题


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?


回答1:


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"



回答2:


Install the NuGet package Microsoft.TeamFoundationServer.ExtendedClient.




回答3:


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




回答4:


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)"
}


来源:https://stackoverflow.com/questions/51674032/unable-to-find-type-microsoft-teamfoundation-client-teamfoundationserverfactory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!