TFS2015ビルド定義から情報を取得しようとしています。 XAML形式のビルド定義は約100あり、新しい2015形式のビルド定義は約50です。 サーバーは社内チーム基盤サーバーです。 (Microsoft Visual Studio Team Foundation Server バージョン15.105.25910.0)TFSサーバーAPIは、XAMLビルド定義のみを一覧表示します。
私は残りの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();
}
}
}
[OK]を、多分私はMicrosoft.TeamFoundationServer.ExtendedClient読ん高速にそれを読む:」..Becauseは、すべてのAPIはRESTのAPIとして、現在、TFS 2015またはVSOで提供されていない、あなたのケースがあるように予定されていますこのパッケージを使わなければならない... "だから私はすべてがこれにあったと思った。 (したがって、名前が拡張された " –
私は残りのAPIを試みたが、私はSystem.Net.Http.HttpRequestExceptionを動作させるためにWindows認証を取得していませんでした:レスポンスステータスコードは成功を示していません:401(無認可) –
UseDefaultCredentials = true; WebClientオブジェクトに? –