我正在尝试编写一个脚本来使用 powershell 连接到 TFS,但是我陷入了实际连接的部分
$credentialProvider = new-object Microsoft.TeamFoundation.Client.UICredentialsProvider
$collection = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($uri, $credentialProvider)
它给出一个错误,表示找不到类型
[错误]新对象:找不到类型[错误]
[Microsoft.TeamFoundation.Client.UICredentialsProvider]:验证
包含此类型的 [ERROR] 程序集已加载。
好吧,我首先尝试这样做,但没有帮助
[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 2013 或更低版本时,Team Foundation Server 客户端对象模型过去会安装到全局程序集缓存。因此,它们总是很容易从任何脚本加载。
在 Team Explorer 和 Visual Studio 2015 及更高版本中,包不再全局注册。同时,Microsoft 更改了许可证,使这些程序集可以与您的应用程序一起分发,并发布了 NuGet 包以使分发更容易。
处理需要 TFS 客户端对象模型的场景的正确方法是将它们与脚本打包或使用 Nuget 按需下载。
您可能需要也可能不需要许多软件包,具体取决于您在脚本中执行的操作:
传统客户端对象模型:
- https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/ https://www.nuget.org/packages/Microsoft.TeamFoundationServer.Client/
- https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/ https://www.nuget.org/packages/Microsoft.TeamFoundationServer.ExtendedClient/
新型 REST API 对象模型:
- https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Client/ https://www.nuget.org/packages/Microsoft.VisualStudio.Services.Client/
- https://www.nuget.org/packages/Microsoft.VisualStudio.Services.InteractiveClient/ https://www.nuget.org/packages/Microsoft.VisualStudio.Services.InteractiveClient/
您可以使用这个小片段来动态获取 nuget.exe 和依赖项:https://stackoverflow.com/a/26421187/736079 https://stackoverflow.com/a/26421187/736079或使用install-package
这是在 powershell v5 中引入的。
Note:如果您正在更新或创建新脚本,建议切换到新型 REST API 和对象模型 https://learn.microsoft.com/en-us/vsts/integrate/get-started/client-libraries/samples随之而来的是。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)