Visual Studio Command for going to a specific item

2019-08-06 02:53发布

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.

3条回答
我只想做你的唯一
2楼-- · 2019-08-06 03:03

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...

查看更多
一纸荒年 Trace。
3楼-- · 2019-08-06 03:04

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.

查看更多
相关推荐>>
4楼-- · 2019-08-06 03:15

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;
    }
查看更多
登录 后发表回答