2017-06-06 103 views
1

使用c#,我以前能夠在使用InformationNodeConverters.GetAssociatedChangesets(IBuildDetail)的XAML構建過程中從TFS 2012獲取關聯的變更集。我從CodeActivityContext.GetExtension<IBuildDetail>()獲得了IBuildDetail。如何從TFS 2017中構建相關的變更集?

現在,我使用的是2017年的TFS構建過程,我試着用下面的代碼類似的東西,但它沒有返回的變更。

上述
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); 

一切似乎工作,構建成功返回,但changeSets.Count()爲0的時候,其實應該有一些變更集返回。

是否有一個建議的更改上面的代碼中,或者可替換的方式來做到這一點?或者這只是在TFS 2017中不再起作用?

+0

難道我需要提供足夠的憑據,以便能夠查看更改集?這看起來很奇怪,因爲我可以成功查看關於構建的其他細節。 –

回答

2

我能夠用我所相信的是包裝的REST API來做到這一點:Microsoft.TeamFoundation.Build2.WebApi.dll

參見:https://social.msdn.microsoft.com/Forums/vstudio/en-US/838da6a7-1dea-4d61-aaad-b789e23c64f2/how-to-get-associated-changesets-from-build-in-tfs-2017?forum=tfsgeneral

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; 
2

微軟更新TFS使用REST API。我認爲this REST API call會讓你想要你想要的。

這裏給.NET client libraries一個鏈接,使REST調用。

另外,如果你不是已經知道,微軟將棄用XAML構建。有關更多信息,請參閱this blog post

+0

對不起,如果我不清楚。我不再使用XAML構建過程,但仍然運行代碼來定製構建。我想我正在尋找一些特定的方式來獲取變更集,無論是通過REST API調用(我還沒有成功),或者我嘗試使用上面的客戶端庫。 –

+0

還有對API的版本4.1預覽文檔:獲取生成更改(https://docs.microsoft.com/en-us/rest/api/vsts/build/builds/get%20build%20changes) – BojanCG

相關問題