从VssConnection请求版本控制服务器(客户端)

时间:2018-05-22 15:14:26

标签: tfs azure-devops

逗人

请帮我使用Microsoft.VisualStudio.Services.Client.15.134.0-preview软件包中的VssConnection

我需要获取工作空间的挂起更改,查询冲突和提交 这是我用TfsTeamProjectCollection和

做的
var vssCred = new VssClientCredentials();

using (TfsTeamProjectCollection collection = new TfsTeamProjectCollection(uri, vssCred))
{
    collection.Authenticate();

    var scs = collection.GetService<VersionControlServer>();

    var scsProject = scs.GetTeamProject(teamProjectName);
    var workspace = scsProject.VersionControlServer.GetWorkspace(localPath);

    var pending = scs.QueryPendingSets(new string[] { "$/" }, RecursionType.Full, workspace.Name, loginName);
    if (pending.Any())
    {
        var pendingChanges = new[] { pending.First().PendingChanges.First() };

        var validation = workspace.EvaluateCheckin2(CheckinEvaluationOptions.Conflicts, pendingChanges, "", null, null);
        var conflicts = validation.Conflicts;
        if (conflicts != null && conflicts.Any())
        {
            var message = string.Join("\r\n", conflicts.Select(_ => string.Format("{0} {1}", _.Message, _.ServerItem)));
            throw new ArgumentException(string.Format("conflict was found\r\n{0}", message));
        }
        var res = workspace.CheckIn(pendingChanges, "test checkin");

        TestContext.WriteLine("checked in {0}", res);
    }

}

但是vsts integration samples使用VssConnection对象 如何从VssConnection实例获取相同的VersionControlServer?

我试图找到Microsoft.TeamFoundation.VersionControl.Client.WebAPi(如Microsoft.TeamFoundation.WorkItemTracking.WebApi)但失败了。

var vssCred = new VssClientCredentials();
using (VssConnection connection = new VssConnection(uri, vssCred))
{
    var prj = connection.GetClient<ProjectHttpClient>();

    var p = prj.GetProject(teamProjectName).Result;

    //i'd like to get prj.VersionControl here       

    //or something like var scs = connection.GetService<VersionControlServer>();
}

是否可以从VssConnection获取versionControlServer?我应该继续使用TfsTeamProjectCollection来完成这项任务吗?

1 个答案:

答案 0 :(得分:0)

您可以像以前一样使用TfsTeamProjectCollection,因为VssConnection中有 no 工作空间方法:

TfvcHttpClient tfvcClient = connection.GetClient<TfvcHttpClient>();
List <TfvcItem> tfvcItems = tfvcClient.GetItemsAsync("$/", VersionControlRecursionType.OneLevel).Result;

更多示例,您可以参考以下链接:

https://docs.microsoft.com/en-us/vsts/integrate/get-started/client-libraries/samples?view=vsts