问题
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