tf.exe 和 tfpt.exe 如何根据执行目录建立与 TFS 实例的连接?

发布于 2024-11-30 00:11:28 字数 1062 浏览 1 评论 0原文

我正在使用 TFS 对象模型在命令行上进行一些工作,并且我希望重现 tf.exe 和 tfpt.exe 中看到的工作区检测行为,而不会由于我自己的特定实现而引入工件。目前,我的脚本需要的信息比 tf.exe 需要的信息更多 - 我的大量参数只是为了实例化连接。

具体来说,我必须要求用户显式传入服务器 Uri (tfsUriString) 和集合名称 (tfsCollectionName),但这似乎没有必要且烦人,因为 tf.exe 能够做到这一点。

    Uri tfsUri = new Uri(tfsUriString);
    TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
    ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);
    CatalogNode collectionNode = collectionNodes.Where(node => node.Resource.DisplayName == tfsCollectionName).SingleOrDefault();
    Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
    TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
    var vcServer = teamProjectCollection.GetService<VersionControlServer>();

可以使用哪些类和方法以与 tf.exe 相同的方式执行此检测?

I'm doing some work at the command line using using the TFS object model, and I want to reproduce the workspace-detection bahavior seen in tf.exe and tfpt.exe without introducing artifacts because of my own particular implementation. Currently, my scripts require more information than what tf.exe needs--a significant amount of my parameters are there simply to instantiate the connection.

Specifically, I have to require users to explicitly pass in the server Uri (tfsUriString) and the collection name (tfsCollectionName), but this seems needless and annoying since tf.exe is able to do it.

    Uri tfsUri = new Uri(tfsUriString);
    TfsConfigurationServer configurationServer = TfsConfigurationServerFactory.GetConfigurationServer(tfsUri);
    ReadOnlyCollection<CatalogNode> collectionNodes = configurationServer.CatalogNode.QueryChildren( new[] { CatalogResourceTypes.ProjectCollection }, false, CatalogQueryOptions.None);
    CatalogNode collectionNode = collectionNodes.Where(node => node.Resource.DisplayName == tfsCollectionName).SingleOrDefault();
    Guid collectionId = new Guid(collectionNode.Resource.Properties["InstanceId"]);
    TfsTeamProjectCollection teamProjectCollection = configurationServer.GetTeamProjectCollection(collectionId);
    var vcServer = teamProjectCollection.GetService<VersionControlServer>();

What classes and methods can be used to perform this detection in the same way that tf.exe does?

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

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

发布评论

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

评论(1

旧时模样 2024-12-07 00:11:28

Team Foundation Server 客户端使用工作区缓存,其中包含用户在当前计算机上使用的每个团队项目集合的所有工作区。 tf.exe 使用此缓存来确定要用于命令行上给定路径的 TfsTeamProjectCollectionWorkspace

您可以通过以下方式获取特定本地路径的缓存 WorkspaceInfo

Workstation.Current.GetLocalWorkspaceInfo(localPath)

或者您可以通过调用获取整个工作区缓存:

Workstation.Current.GetAllLocalWorkspaceInfo()

WorkspaceInfo.ServerUri 属性将包含您的服务器 URI可以用来创建 TfsTeamProjectCollection

Team Foundation Server clients use a workspace cache that contains all the user's workspaces for each Team Project Collection that they've used from the current machine. tf.exe uses this cache to determine the TfsTeamProjectCollection and Workspace to use for the paths given on the command line.

You can get the cached WorkspaceInfo for a particular local path by using:

Workstation.Current.GetLocalWorkspaceInfo(localPath)

Or you can get the entire workspace cache by calling:

Workstation.Current.GetAllLocalWorkspaceInfo()

The WorkspaceInfo.ServerUri property will contain the server URI you can use to create a TfsTeamProjectCollection with.

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