tf.exe 和 tfpt.exe 如何根据执行目录建立与 TFS 实例的连接?
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Team Foundation Server 客户端使用工作区缓存,其中包含用户在当前计算机上使用的每个团队项目集合的所有工作区。
tf.exe
使用此缓存来确定要用于命令行上给定路径的TfsTeamProjectCollection
和Workspace
。您可以通过以下方式获取特定本地路径的缓存
WorkspaceInfo
:或者您可以通过调用获取整个工作区缓存:
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 theTfsTeamProjectCollection
andWorkspace
to use for the paths given on the command line.You can get the cached
WorkspaceInfo
for a particular local path by using:Or you can get the entire workspace cache by calling:
The
WorkspaceInfo.ServerUri
property will contain the server URI you can use to create aTfsTeamProjectCollection
with.