With c#, I was previously able to get associated changesets from TFS 2012 during a XAML build process using InformationNodeConverters.GetAssociatedChangesets(IBuildDetail)
. I got the IBuildDetail from CodeActivityContext.GetExtension<IBuildDetail>()
.
Now that I'm using the TFS 2017 build processes, I am trying to do something similar with the code below, but it is not returning changesets.
var teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://ourtfsserver:8080/tfs/DefaultCollection"));
var versionControlServer = teamProjectCollection.GetService<VersionControlServer>();
var buildServer = teamProjectCollection.GetService<IBuildServer>();
var build = buildServer.GetBuild(new Uri(string.Format("vstfs:///Build/Build/{0}", "3807")));
var changeSets = InformationNodeConverters.GetAssociatedChangesets(build);
All of the above seems to work, and a build is returned successfully, but changeSets.Count() is 0, when in fact there should be some changesets returned.
Is there a suggested change to the code above, or an alternate way to do this? Or does this just no longer work in TFS 2017?
I was able to do this by using what I believe are wrappers to the REST API: Microsoft.TeamFoundation.Build2.WebApi.dll
using Microsoft.TeamFoundation.Build.WebApi;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.WebApi;
using System;
using System.Net;
var u = new Uri("http://ourtfsserver:8080/tfs/DefaultCollection/");
var c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("username", "password", "domain")));
var connection = new VssConnection(u, c);
var buildServer = connection.GetClient<BuildHttpClient>();
var changesets = buildServer.GetBuildChangesAsync("projectname", 3807).Result;