gpt4 book ai didi

powershell - 无法找到类型 [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]

转载 作者:行者123 更新时间:2023-12-02 22:33:59 27 4
gpt4 key购买 nike

我正在尝试编写一个脚本来使用 powershell 连接到 TFS,但是我卡在了实际连接的部分

$credentialProvider = new-object Microsoft.TeamFoundation.Client.UICredentialsProvider
$collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri, $credentialProvider)

报错说找不到类型

[ERROR] New-object : Cannot find type [ERROR] [Microsoft.TeamFoundation.Client.UICredentialsProvider]: verify that the [ERROR] assembly containing this type is loaded.

好吧,我首先尝试这样做,但没有帮助

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.WorkItemTracking.Client")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")

我的开发环境中只安装了 Visual Studio 2015。是否有一些我缺少的组件是使用 powershell 与 TFS 交互所必需的?

此外,我不知道该脚本将从何处运行(它不会来自开发机器),大概是从可以直接访问 TFS 服务器的机器(可能使用 Team Explorer)运行。

最佳答案

在您安装 Team Explorer 2013 或更低版本时,Team Foundation Server 客户端对象模型曾经被安装到全局程序集缓存中。因此,它们总是很容易从任何脚本加载。

在 Team Explorer 和 Visual Studio 2015 及更高版本中,包不再全局注册。同时,Microsoft 更改了许可证并使这些程序集可以随您的应用程序一起分发,并发布了一个 NuGet 包以使分发更容易。

处理需要 TFS 客户端对象模型的情况的正确方法是将它们与脚本打包或使用 Nuget 按需下载。

根据您在脚本中执行的操作,您可能需要也可能不需要许多软件包:

传统客户端对象模型:

新型 REST API 对象模型:

您可以使用这个小片段来动态获取 nuget.exe 和依赖项:https://stackoverflow.com/a/26421187/736079或者使用 powershell v5 中引入的 install-package

注意:如果您正在更新或创建新脚本,建议切换到 the new-style REST API's and the object model随之而来的是。

关于powershell - 无法找到类型 [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49366947/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com