简体   繁体   中英

Visual Studio Command for going to a specific item in source control explorer

Im looking for a way to automatically open Source Control Explorer from inside a plugincode. So far I managed to open it by executing the command

View.TfsSourceControlExplorer

However, this does not seem to accept any arguments.

My goal here is to do something like this:

destination = "$/dev/framework/someFolder";

_dteObject.ExecuteCommand("View.TfsSourceControlExplorer", destination);

Which will them show me Source Control Explorer in the specified destination.

To anwser CSharpie's comment :

Also there seems to be a bug, if you call navigate to a file of the same directory as the explorer currently is in, everything will disappear.

I had the same problem, got two ways of solving this :

  • Truncate the filename from the path to only Navigate to folders.
  • Navigate to root first ("$/"), then navigate to the file you want.

Both works fine in VS2013.

And thanks for the "Application.DoEvent()" fix when the SourceControlExplorer's not opened.

Use the following code to show Source Control Explorer in the specified destination:

    public void SelectFolder(string path)
    {
        dte.ExecuteCommand("View.TfsSourceControlExplorer");

        Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt explorer =
            GetSourceControlExplorer();
        if (explorer != null)
            explorer.Navigate(path);
    }

    private Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt GetSourceControlExplorer()
    {
        Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt versionControl =
            dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt") as
                Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt;
        if (versionControl == null)
            return null;

        return versionControl.Explorer;
    }

I believe this is not possible. The source explorer detects the team project and drops you at the root of the team project node. $/myproject/ ..

Happy to be proven wrong on this one...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM