使用Azure DevOps Services .NET SDK。
如何获取变更集中的文件列表?这些都不起作用...?
var serverUrl = new Uri(url);
//var clientCredentials = new VssClientCredentials(username, password);
var clientCredentials = new VssBasicCredential("", accessToken);
var connection = new VssConnection(serverUrl, clientCredentials);
var sourceControlServer = connection.GetClient<TfvcHttpClient>(); // connect to the TFS source control subpart
var changesets = sourceControlServer.GetChangesetsAsync(project).Result;
foreach (var changeset in changesets.OrderBy(x => x.CreatedDate))
{
changeset.Links // this is null
var items = sourceControlServer.GetItemsByChangesetPagedAsync(
1000, changeset.ChangesetId).Result;
var changes = sourceControlServer.GetChangesetChangesPagedAsync(
changeset.ChangesetId, 1000).Result;
}
答案 0 :(得分:1)
此代码与Azure DevOps Service和nuget软件包Microsoft.TeamFoundationServer.Client 15.131.1一起使用:
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.TeamFoundation.Core.WebApi;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.TeamFoundation.TestManagement.WebApi;
using Microsoft.TeamFoundation.WorkItemTracking.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Collections.Generic;
namespace TFRestApiApp
{
class Program
{
static readonly string TFUrl = "service_url"; // for devops azure
static readonly string UserPAT = "<your_pat>"; //https://docs.microsoft.com/en-us/azure/devops/organizations/accounts/use-personal-access-tokens-to-authenticate?view=azure-devops
static WorkItemTrackingHttpClient WitClient;
static BuildHttpClient BuildClient;
static ProjectHttpClient ProjectClient;
static GitHttpClient GitClient;
static TfvcHttpClient TfvsClient;
static TestManagementHttpClient TestManagementClient;
static void Main(string[] args)
{
try
{
ConnectWithPAT(TFUrl, UserPAT);
List<TfvcChange> chs = TfvsClient.GetChangesetChangesAsync(344).Result;
foreach (TfvcChange ch in chs)
Console.WriteLine("{0}: {1}", ch.ChangeType.ToString(), ch.Item.Path);
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex.Message);
if (ex.InnerException != null) Console.WriteLine("Detailed Info: " + ex.InnerException.Message);
Console.WriteLine("Stack:\n" + ex.StackTrace);
}
}
#region create new connections
static void InitClients(VssConnection Connection)
{
WitClient = Connection.GetClient<WorkItemTrackingHttpClient>();
BuildClient = Connection.GetClient<BuildHttpClient>();
ProjectClient = Connection.GetClient<ProjectHttpClient>();
GitClient = Connection.GetClient<GitHttpClient>();
TfvsClient = Connection.GetClient<TfvcHttpClient>();
TestManagementClient = Connection.GetClient<TestManagementHttpClient>();
}
static void ConnectWithPAT(string ServiceURL, string PAT)
{
VssConnection connection = new VssConnection(new Uri(ServiceURL), new VssBasicCredential(string.Empty, PAT));
InitClients(connection);
}
#endregion
}
}
我的存储库的结果