TFS 2010 以编程方式确定项目分支

发布于 2024-11-28 14:43:34 字数 212 浏览 0 评论 0原文

如何以编程方式确定该文件属于哪个分支?我花了 3 个小时试图解决这个问题,但没有结果。我找到了这个主题,但这不是我想要的: 如何以编程方式获取有关 TFS 中分支的信息?

How can I determine programatically which branch this file belongs to? I've spent 3 hours trying to figure this out with no results. I found this topic but it's not what I want: How to programmatically get information about branches in TFS?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眼眸 2024-12-05 14:43:34

我有一个非常相似的问题。我找到了一个解决方案,这里是代码:

...
// get all branches
VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer));
BranchObject[] allBranches = vcs.QueryRootBranchObjects(RecursionType.Full);

string myItem = "$/My Project/some Path including the branch/myFile.txt";

foreach(BranchObject branch in allBranches)
{
  if(myItem.Contains(branch.Properties.RootItem.Item))
  {
    // branch is the branch to which the item belongs! :)
  }
}
...

我希望这可以帮助解决这个问题的人,我认为操作员已经解决了它(自从他问这个问题以来已经有一段时间了)。

I had a very similar problem. I found a solution to it, here is the code:

...
// get all branches
VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer));
BranchObject[] allBranches = vcs.QueryRootBranchObjects(RecursionType.Full);

string myItem = "$/My Project/some Path including the branch/myFile.txt";

foreach(BranchObject branch in allBranches)
{
  if(myItem.Contains(branch.Properties.RootItem.Item))
  {
    // branch is the branch to which the item belongs! :)
  }
}
...

I hope this helps someone with this problem, I think the op has already solved it (it's been a while since he asked the question).

盗琴音 2024-12-05 14:43:34

我发现获取特定文件的分支信息的唯一方法是使用 VersionControlServer.QueryBranchObjects 查询文件夹结构中的每个可能的分支,一直到根。

但是,您可以做出一些假设并相当有效地完成 - 因为一个分支不能位于 tfs 2010 中的另一个分支中。找到正在签入的所有文件的路径的公共子集并测试这些文件,如果没有一个是分支,那么它们就不是属于同一分支。

The only way I've found to get branch info for a specific file is to use VersionControlServer.QueryBranchObjects to query each possible branch in a folder structure all the way up to the root.

However you can make a few assumptions and do it fairly efficiently - as a branch cannot be in another branch in tfs 2010. Find the common subset of paths of all files being checked in and test those, if none are branches then they don't belong to same branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文