我正在尝试从我的TFS服务器获取最新的构建详细信息,但以下行引发了一个空引用异常。
ITestManagementTeamProject project = tms.GetTeamProject(proj.Name);
“Microsoft.TeamFoundation.TestManagement.Client.dll中发生了'System.NullReferenceException'类型的未处理异常
附加信息:对象引用未设置为对象的实例。“
这是周围的代码
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.TestManagement.Client;
class Program
{
static void Main(string[] args)
{
TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(TfsTeamProjectCollection.GetFullyQualifiedUriForName("http://tfs2013-99-228:8080/tfs/si nhss"));
tfs.EnsureAuthenticated();
VersionControlServer vcs = tfs.GetService<VersionControlServer>();
ITestManagementService tms = tfs.GetService<ITestManagementService>();
TeamProject[] teamProjects = vcs.GetAllTeamProjects(true);
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
foreach (TeamProject proj in teamProjects)
{
IBuildDefinition[] defs = buildServer.QueryBuildDefinitions(proj.Name);
System.Console.WriteLine(string.Format("Team Project: {0}", proj.Name));
foreach (IBuildDefinition def in defs)
{
IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(proj.Name, def.Name);
spec.MaxBuildsPerDefinition = 10;
spec.QueryOrder = Microsoft.TeamFoundation.Build.Client.BuildQueryOrder.FinishTimeDescending;
spec.DefinitionSpec.Name = def.Name;
spec.Status = Microsoft.TeamFoundation.Build.Client.BuildStatus.All;
IBuildQueryResult builds = buildServer.QueryBuilds(spec);
if (builds.Builds.Length > 0)
{
var buildDetail = builds.Builds[0];
ITestManagementTeamProject project = tms.GetTeamProject(proj.Name);
System.Console.WriteLine(string.Format(" {0} - {1} - {2}", def.Name, buildDetail.Status.ToString(), buildDetail.FinishTime));
}
}
System.Console.WriteLine();
}
}
}
答案 0 :(得分:1)
您的推荐可能有问题。我测试了您的脚本,它适用于安装的 Microsoft Team Foundation Server扩展客户端包。
PM&GT;安装包Microsoft.TeamFoundationServer.ExtendedClient -Version 15.112.1