How do i get current Branch path from Source control explorer using VS package

僤鯓⒐⒋嵵緔 提交于 2019-12-11 12:02:26

问题


I have created VS extension that creates a menu command on Source control explorer by right click on that it open custom form,Now i want to display current TFS path(from where user right click) in that custom form.Same as TFS "Branching and Merging => Branch" Source Path.

Any help Appreciate.


回答1:


You can use the VersionControlExplorerExt object with its properties SelectedItems, CurrentFolderItem, etc. From a package it would be something like:

  private void MenuItemCallback(object sender, EventArgs e)
  {
     Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt versionControlExt;
     Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt versionControlExplorerExt;
     EnvDTE.DTE dte;

     try
     {
        dte = base.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

        versionControlExt = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") 
           as Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt;

        versionControlExplorerExt = versionControlExt.Explorer;

        MessageBox.Show(versionControlExplorerExt.CurrentFolderItem.LocalPath);

     }
     catch (Exception ex)
     {
        MessageBox.Show(ex.ToString());
     }

  }



回答2:


The extensibility for Source Control Explorer should be exposed through the VersionControlExt.Explorer class. The VersionControlExt.Explorer.SelectedItems property should contain the server paths for the selected items. Here is an old blog post that might also have some useful information for writing extensions.



来源:https://stackoverflow.com/questions/30027908/how-do-i-get-current-branch-path-from-source-control-explorer-using-vs-package

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