我使用TFS客户端API尝试查询TFS 2010实例。 我需要能够做到以下
然后能够遍历此列表并获取项目的元数据(理想情况下是文件和文件夹名称)
我认为我需要在VersionControlServer类上使用QueryXXX方法,但找不到有关如何使用它的任何有用或明确的示例。
我已经看到有GetLastestChangesetId方法,但这看起来不像是可以限定为特定项目或目录。
答案 0 :(得分:14)
这非常简单:
var tfsUrl = "http://myTfsServer:8080/tfs/defaultcollection";
var sourceControlRootPath = "$/MyTeamProject";
var tfsConnection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsUrl));
var vcs = tfsConnection.GetService<VersionControlServer>();
var changeSets = vcs.QueryHistory(sourceControlRootPath, RecursionType.Full);
foreach (var c in changeSets)
{
var changeSet = vcs.GetChangeset(c.ChangesetId);
foreach (var change in changeSet.Changes)
{
// All sorts of juicy data in here
}
}
答案 1 :(得分:0)
2021 年,使用 azure devOps Tfs Client Api
根据 documentation,Api 用于跟踪 Tfs 服务器。
Azure DevOps 服务 | Azure DevOps 服务器 2020 | Azure DevOps 服务器 2019 | TFS 2018 - TFS 2013
此处使用的命名空间:
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.VisualStudio.Services.WebApi;
如下创建VssConnection,
string myTfsProjectUri = "url path to your tfs project";
VssConnection myConnection = new VssConnection( new Uri( collectionUri ), new VssClientCredentials() );
如下创建TfvcHttpClient客户端,
TfvcHttpClient myVersionControlHttpClient = myConnection.GetClient<TfvcHttpClient>();
使用如下搜索条件获取变更集(给定的片段查找给定的 fromCheckInId 和 toCheckInId 之间的所有签入),
List<TfvcChangesetRef> changeSets = VersionControlHttpClient
.GetChangesetsAsync(
projectName, /* Tfs Project name */
null, /* Max Comment length, can be null */
null, /* Number of results to Skip, can be null */
null, /* Maximum Number of results to return, can be null */
null, /* Results are sorted by ID in descending order by default. Use id asc to sort by ID in ascending order */
new TfvcChangesetSearchCriteria()
{
ItemPath = branchName, /* Path to Branch under given project */
FromId = fromCheckinId, /* From check-in id to start search */
ToId = toCheckinId /* To check-in id to end search */
} ).Result;
此 API 也可用于 FromDate 和 ToDate 搜索条件。
欲了解更多信息,请阅读官方documentation