TeamFoundationServerFactory

TeamFoundationServerFactory

本文介绍了即使DLL已在GAC中,也找不到[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写PowerShell脚本,但是遇到了错误.

I am trying to write a PowerShell script, but I'm running into an error.

当我的脚本上线

我得到了错误:

InvalidOperation:(Microsoft.TeamF ... onServerFactory:TypeName)[],RuntimeException

InvalidOperation: (Microsoft.TeamF...onServerFactory:TypeName) [], RuntimeException

尽管我的问题与此问题非常相似 ,我已经知道Microsoft.TeamFoundation.Client.dll文件及其依赖项在GAC中.另一个问题从来没有阐明这一点,我认为这可能会影响我将得到的答案.

Though my question is very similar to this question, I already know that the Microsoft.TeamFoundation.Client.dll file and its dependencies are in the GAC. The other question never clarifies that, and I think that might affect the answers I will get.

在发生错误的那一行之前,我有许多Add-Type语句来确保我需要的引用在那里.这些语句中有一个指向Microsoft.TeamFoundation.Client.dll的Add-Type语句.我已验证它的位置正确.

Before the line where the error occurs, I have a number of Add-Type statements to make sure the references I need are there. Among these statements is an Add-Type statement pointing to the Microsoft.TeamFoundation.Client.dll. I have verified that it's looking in the right location.

我还包括了一条try-catch语句,该语句会在出现任何错误的情况下打印加载程序异常.目前,该脚本可以成功通过这些语句,而不会遇到catch块.

I've also included a try-catch statement that prints the loader exceptions if anything goes wrong there. Currently, the script is successfully making it through those statements without hitting the catch block.

鉴于我知道相应的dll已存在于GAC中,什么可能导致此错误,以及如何解决该错误?

Given that I know that the relevant dll is already in the GAC, what could cause this error, and how would I fix it?

推荐答案

我建议您直接从目录中加载程序集,例如:

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
    }

您还可以将程序集复制到特殊文件夹(例如当前项目中的Lib文件夹)

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"
...

这篇关于即使DLL已在GAC中,也找不到[Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 01:18