5

我正在尝试使用 TFS API 获取测试计划。

TfsTeamProjectCollection tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://xxxxxxx:8080/tfs/DefaultCollection"));

var service = (ITestManagementService)tfs.GetService(typeof(ITestManagementService));

变量“服务”总是返回 null。

你有什么想法,为什么?

4

2 回答 2

4

在调用 Get Service 命令之前,请尝试确保您已通过团队项目集合的身份验证。这个代码片段对我来说是正确的:

TfsTeamProjectCollection tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("https://tfs.companyname.com/tfs/DefaultCollection"));
tpc.EnsureAuthenticated();

ITestManagementService service = tpc.GetService<ITestManagementService>();
于 2012-10-12T15:56:05.923 回答
2

也许您正在链接不同版本的参考程序集,混合不同版本的 Visual Studio 程序集?例子:

  • Microsoft.TeamFoundation.Clientv11.0 (VS 2012)
  • Microsoft.TeamFoundation.TestManagement.Clientv12.0 (VS 2013)

我有同样的问题,GetService<ITestManagementService>()总是返回 null,即使GetService<VersionControlServer>()会返回好的(非 null)值。

MSDN中发布的解决方案- VersionControlServer 总是返回 null对我有用:我引用了一些 v11.0 (VS2012) 和 v12.0 (VS2013) 程序集。更改对 v11.0 的所有引用为我修复了它。

于 2014-07-29T20:42:48.210 回答