Get current TFS connection in a Visual Studio addin

那年仲夏 提交于 2019-12-07 06:26:06

问题


I'm working on a Visual Studio 2010 add-in, and I'm trying to figure out how to determine the currently connected TFS server. I'm guessing I need to use DTE, but I'm having a brain cramp figuring out where to get the info.


回答1:


I suggest you check out the Microsoft.TeamFoundation.VersionControl.Client.Workstation.GetLocalWorkspaceInfo method, in result you have an object and access ServerUri property

See this documentation on MSDN for more details.




回答2:


Robaticus originally edited the question with the solution. Converted it to a Community Wiki answer:

Actually, I may have found the answer, which I culled from a couple places.

var dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

TeamFoundationServerExt ext = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.TeamFoundationServerExt") as TeamFoundationServerExt;

TeamFoundationServer tfs = new TeamFoundationServer(ext.ActiveProjectContext.DomainUri);
VersionControlServer vcs = tfs.GetService<VersionControlServer>();

var changes = vcs.GetPendingChanges(null);


来源:https://stackoverflow.com/questions/3339916/get-current-tfs-connection-in-a-visual-studio-addin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!