无法找到类型 [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory] [英] Unable to find type [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]

查看:105
本文介绍了无法找到类型 [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to write a script to connect to TFS using powershell, however I'm stuck on the part of actually connecting

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

它给出了一个错误,说它找不到类型

It gives an error that says it cannot find the type

[错误] 新对象:找不到类型 [错误][Microsoft.TeamFoundation.Client.UICredentialsProvider]:验证加载了包含此类型的 [ERROR] 程序集.

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

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

Well I tried to do this first, but it did not help

[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 接口的要求?

I only have Visual Studio 2015 installed on my development environment. Is there some component that I'm missing that is a requirement for interfacing with TFS using powershell?

此外,我不知道这个脚本将从哪里运行(它不会来自开发机器),大概是从可以直接访问 TFS 服务器的机器上运行,也许使用团队资源管理器.

Furthermore I don't know where this script will be run from (it wont be from a development machine), presumably from a machine that has access to TFS server directly maybe using Team Explorer.

推荐答案

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

The Team Foundation Server Client Object Model used to be installed to the Global Assembly Cache when you installed Team Explorer 2013 or below. Because of that, they were always easy to load from any script.

使用团队资源管理器和 Visual Studio 2015 及更高版本,包不再全局注册.同时,Microsoft 更改了许可证并使这些程序集可随您的应用程序一起分发,并发布了 NuGet 包以简化分发.

With Team Explorer and Visual Studio 2015 and up, the packages are no longer registered globally. At the same time, Microsoft changed the license and made these assemblies distributable with your application and released a NuGet package to make distribution easier.

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

The proper way to handle scenarios where you need the TFS Client Object Model is to package them with your script or the download them on-demand using Nuget.

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

There are a number of packages that you may or may not need depending on what you are doing from your scripts:

传统客户端对象模型:

新型 REST API 对象模型:

New-style REST API object model:

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

You can use this little snippet to fetch nuget.exe and the dependencies on the fly: https://stackoverflow.com/a/26421187/736079 or use the install-package that was introduced in powershell v5.

注意:如果您要更新或创建新脚本,建议切换到 新型 REST API 和与之相伴的对象模型.

Note: If you're updating or creating new scripts, it's recommended to switch to the new-style REST API's and the object model that goes along with that.

这篇关于无法找到类型 [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆