无法通过网络连接到 TFS2015 服务器 api
Trouble connecting to the TFS2015 server via web api
我一直在尝试通过网络连接到我们的 TFS2015 服务器 api。我以前没有这样做过。我的目标是获得最后一次成功构建,从他那里获取所有变更集,并为每个变更集提供一个信息,该信息是从哪个分支转发到发布分支的。我无法连接到它并且不确定我的下一步是什么。
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
try
{
VssConnection connection = new VssConnection(new Uri("http://srv-tfs2015:8080/tfs/"), new VssCredentials(useDefaultCredentials: true));
Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient buildKlijent = connection.GetClient<Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient>();
var lastBuild = buildKlijent.GetLatestBuildAsync("Argosy", "Argosy32New");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
lastBuild 包含带有消息的 VssResourceNotFountException:
API 资源位置 54481611-01f4-47f3-998f-160da0f0c229 未在 http://srv-tfs2015:8080/tfs/.
上注册
构建驻留在团队项目 Argosy 中,它是服务器上 ArgosyCollection 的一部分,它是一个 XAML 构建定义。不确定这是否有任何区别。
你能帮我指出正确的方向吗?
Get Latest says you have to use rest api version 5.1. But TFS 2015 (API and TFS version mapping) supports only 2.4. So you have to use Get a list of build 的文档并通过 GetBuildsAsync
方法检测结果列表中的最后一个构建。
查看构建定义的最后 10 个构建的示例:
private static void ListBuildDefinitions(string TeamProjectName)
{
List<BuildDefinitionReference> buildDefs = BuildClient.GetDefinitionsAsync(TeamProjectName).Result;
foreach(BuildDefinitionReference buildDef in buildDefs)
{
Console.WriteLine("+================BUILD DEFINITION=======================================================");
Console.WriteLine(" ID:{0, -9}|NAME:{1, -35}|PATH:{2}", buildDef.Id, buildDef.Name, buildDef.Path);
Console.WriteLine(" REV:{0, -8}|QUEUE:{1, -34}|QUEUE STATUS:{2}", buildDef.Revision, (buildDef.Queue != null) ? buildDef.Queue.Name : "", buildDef.QueueStatus);
ListBuilds(TeamProjectName, buildDef);
}
}
private static void ListBuilds(string TeamProjectName, BuildDefinitionReference buildDef)
{
List<Build> builds = BuildClient.GetBuildsAsync(TeamProjectName, new List<int> { buildDef.Id }).Result;
if (builds.Count > 0)
{
Console.WriteLine("+====================BUILDS================================================================================");
Console.WriteLine("+ ID | NUMBER | STATUS | START DATE | FINISH DATE | COMMITS");
Console.WriteLine("+----------------------------------------------------------------------------------------------------------");
for (int i = 0; i < builds.Count && i < 10; i++)
{
var changes = BuildClient.GetBuildChangesAsync(TeamProjectName, builds[i].Id).Result;
Console.WriteLine(" {0, -12}|{1, -22}|{2, -17}|{3, -20}|{4, -20}|{5}", builds[i].Id, builds[i].BuildNumber, builds[i].Status,
(builds[i].StartTime.HasValue) ? builds[i].StartTime.Value.ToString() : "",
(builds[i].FinishTime.HasValue) ? builds[i].FinishTime.Value.ToString() : "", changes.Count);
}
}
else
Console.WriteLine("+=======================================================================================");
}
在此处检查 TFS 2015 的可用功能:Pre-Version 4.1 REST API documentation
尝试修改Uri,添加项目集合名称和@字符,例如:
VssConnection connection = new VssConnection(new Uri(@"http://srv-tfs2015:8080/tfs/DefaultCollection"), myCredentials);
我一直在尝试通过网络连接到我们的 TFS2015 服务器 api。我以前没有这样做过。我的目标是获得最后一次成功构建,从他那里获取所有变更集,并为每个变更集提供一个信息,该信息是从哪个分支转发到发布分支的。我无法连接到它并且不确定我的下一步是什么。
这是我的代码:
private void button1_Click(object sender, EventArgs e)
{
try
{
VssConnection connection = new VssConnection(new Uri("http://srv-tfs2015:8080/tfs/"), new VssCredentials(useDefaultCredentials: true));
Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient buildKlijent = connection.GetClient<Microsoft.TeamFoundation.Build.WebApi.BuildHttpClient>();
var lastBuild = buildKlijent.GetLatestBuildAsync("Argosy", "Argosy32New");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
lastBuild 包含带有消息的 VssResourceNotFountException:
API 资源位置 54481611-01f4-47f3-998f-160da0f0c229 未在 http://srv-tfs2015:8080/tfs/.
上注册构建驻留在团队项目 Argosy 中,它是服务器上 ArgosyCollection 的一部分,它是一个 XAML 构建定义。不确定这是否有任何区别。
你能帮我指出正确的方向吗?
Get Latest says you have to use rest api version 5.1. But TFS 2015 (API and TFS version mapping) supports only 2.4. So you have to use Get a list of build 的文档并通过 GetBuildsAsync
方法检测结果列表中的最后一个构建。
查看构建定义的最后 10 个构建的示例:
private static void ListBuildDefinitions(string TeamProjectName)
{
List<BuildDefinitionReference> buildDefs = BuildClient.GetDefinitionsAsync(TeamProjectName).Result;
foreach(BuildDefinitionReference buildDef in buildDefs)
{
Console.WriteLine("+================BUILD DEFINITION=======================================================");
Console.WriteLine(" ID:{0, -9}|NAME:{1, -35}|PATH:{2}", buildDef.Id, buildDef.Name, buildDef.Path);
Console.WriteLine(" REV:{0, -8}|QUEUE:{1, -34}|QUEUE STATUS:{2}", buildDef.Revision, (buildDef.Queue != null) ? buildDef.Queue.Name : "", buildDef.QueueStatus);
ListBuilds(TeamProjectName, buildDef);
}
}
private static void ListBuilds(string TeamProjectName, BuildDefinitionReference buildDef)
{
List<Build> builds = BuildClient.GetBuildsAsync(TeamProjectName, new List<int> { buildDef.Id }).Result;
if (builds.Count > 0)
{
Console.WriteLine("+====================BUILDS================================================================================");
Console.WriteLine("+ ID | NUMBER | STATUS | START DATE | FINISH DATE | COMMITS");
Console.WriteLine("+----------------------------------------------------------------------------------------------------------");
for (int i = 0; i < builds.Count && i < 10; i++)
{
var changes = BuildClient.GetBuildChangesAsync(TeamProjectName, builds[i].Id).Result;
Console.WriteLine(" {0, -12}|{1, -22}|{2, -17}|{3, -20}|{4, -20}|{5}", builds[i].Id, builds[i].BuildNumber, builds[i].Status,
(builds[i].StartTime.HasValue) ? builds[i].StartTime.Value.ToString() : "",
(builds[i].FinishTime.HasValue) ? builds[i].FinishTime.Value.ToString() : "", changes.Count);
}
}
else
Console.WriteLine("+=======================================================================================");
}
在此处检查 TFS 2015 的可用功能:Pre-Version 4.1 REST API documentation
尝试修改Uri,添加项目集合名称和@字符,例如:
VssConnection connection = new VssConnection(new Uri(@"http://srv-tfs2015:8080/tfs/DefaultCollection"), myCredentials);