Unable to find [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory] even though dll is already in GAC

白昼怎懂夜的黑 提交于 2019-12-01 13:56:53

I’d suggest you to load assemblies from directory directly, for example:

 $TfsAssembliesPath="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.ServiceBus.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.VisualStudio.Services.Common.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.VisualStudio.Services.WebApi.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.VisualStudio.Services.Client.Interactive.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Core.WebApi.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Common.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.TestManagement.Common.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.ProjectManagement.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Build.Client.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Build.Common.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Git.Client.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.SourceControl.WebApi.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.QueryLanguage.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.DataStoreLoader.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Common.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.WebApi.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Proxy.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.WorkItemTracking.Client.dll"
Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.TestManagement.Client.dll"
    Function CreateWorkItem{

    [string]$tfsCollectionUrl="TFS collection URL"
    [string]$tfsTeamProjectName="team project"

    $teamProjectCollection=[Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($tfsCollectionUrl)
    $ws = $teamProjectCollection.GetService([type]"Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItemStore")
    $proj = $ws.Projects[$tfsTeamProjectName]

    $wit = $proj.WorkItemTypes["Task"]

    #Create a new work item of that type
    $workitem = $wit.NewWorkItem()

    $workItem.Title = "Sample Task Title 3"
    $workItem.Description = "Sample Description"
    $workitem.AreaPath = $tfsTeamProjectName
    $workitem.IterationPath = $tfsTeamProjectName

    $workItem.Save()
    Write-Host "The TFS work item number is: " $workItem.Id
    }

You also could copy assemblies to a special folder (e.g. Lib folder in current project)

    $TfsAssembliesPath="$PSScriptRoot\Libs"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Client.dll"
    Add-Type -Path "$TfsAssembliesPath\Microsoft.TeamFoundation.Common.dll"
...

I've never used this, but I believe this would work. At least I didn't get a type not found error.

using assembly Microsoft.TeamFoundation.Client
using namespace Microsoft.TeamFoundation.Client

$tfs = [TeamFoundationServerFactory]::GetServer($server)

Not that in PS 6, there's no GAC. so you'd have to put the full path to the dll for using assembly.

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