Search code examples
visual-studio-2012tfsvsix

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


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.


Solution

  • 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());
         }
    
      }