我想從TFS2015構建定義中獲取信息。我們在XAML格式中有大約100個構建定義,並且在2015年新格式中有大約50個構建定義。 服務器是內部團隊基礎服務器。 (微軟的Visual Studio Team Foundation Server的 版15.105.25910.0)TFS服務器API只列出XAML構建定義
我不使用REST API,但這裏推薦的Microsoft.TeamFoundationServer.ExtendedClient爲:https://blogs.msdn.microsoft.com/buckh/2015/08/10/nuget-packages-for-tfs-and-visual-studio-online-net-client-object-model/。
這是我的代碼例如:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Serilog;
namespace TFSExperiment
{
class Program
{
// see https://blogs.msdn.microsoft.com/buckh/2015/08/10/nuget-packages-for-tfs-and-visual-studio-online-net-client-object-model/
//Needs nuget package Install-Package Microsoft.TeamFoundationServer.ExtendedClient -Version 14.102.0
// to use serilogg: Install-Package Serilog ; Install-Package Serilog.Sinks.RollingFile
static void Main(string[] args)
{
var myLog = new LoggerConfiguration()
.WriteTo.RollingFile("..\\..\\Applog\\mylog-{Date}.log").CreateLogger();
TfsConfigurationServer configurationServer =
TfsConfigurationServerFactory.GetConfigurationServer(new Uri("https://tfs.inhouseserver2015.org/tfs/"));
ReadOnlyCollection<CatalogNode> collectionNodes =
configurationServer.CatalogNode.QueryChildren(new[] {CatalogResourceTypes.ProjectCollection}, false,
CatalogQueryOptions.None);
CatalogNode defultTfsCol = collectionNodes.AsQueryable().Single(c=>c.Resource.DisplayName.Equals("DefaultCollection"));
Console.WriteLine(defultTfsCol.Resource.DisplayName);
TfsTeamProjectCollection tfsProjectCollection =
configurationServer.GetTeamProjectCollection(new Guid(defultTfsCol.Resource.Properties["InstanceId"]));
tfsProjectCollection.Authenticate();
var buildServer = (IBuildServer)tfsProjectCollection.GetService(typeof(IBuildServer));
ReadOnlyCollection<CatalogNode> projectNodes = defultTfsCol.QueryChildren(
new[] { CatalogResourceTypes.TeamProject },
false, CatalogQueryOptions.None);
foreach (var proj in projectNodes)
{
var buildDefinitionList = new List<IBuildDefinition>(buildServer.QueryBuildDefinitions(proj.Resource.DisplayName));
foreach (var buildDef in buildDefinitionList)
{
Console.WriteLine(buildDef.Name);
myLog.Information($"{buildDef.Id} --{buildDef.Name} --{buildDef.BuildServer.BuildServerVersion} ");
}
}
Console.WriteLine(" Hit any key to exit ");
Console.ReadKey();
}
}
}
好吧,也許我讀了快我讀到Microsoft.TeamFoundationServer.ExtendedClient:」 ..Because不是每個API是在2015年TFS或VSO目前可用的REST API,也將是情況下,你必須使用這個軟件包...「所以我認爲一切都在這個。 (因此名稱擴展名爲「 –
我嘗試了Rest API,但沒有得到Windows身份驗證的工作我只有System.Net.Http.HttpRequestException:響應狀態代碼不表示成功:401(未授權) –
您是否嘗試過設置UseDefaultCredentials = true;在你的WebClient對象上? –