使用“打开相应解决方案”扩展解决方案资源管理器的插件什么时候可用?

发布于 2024-08-30 04:36:55 字数 435 浏览 10 评论 0原文

想象一下一个文件夹结构,其中包含 200 多个项目的解决方案文件,这些文件都属于一个软件。它们中的大多数都会生成共享库,这些共享库在自己的解决方案中包含的其他项目中引用。

如果可以在解决方案资源管理器中右键单击此类引用的程序集,然后有一个上下文菜单项,例如“打开解决方案”和“在新的 Visual Studio 实例中打开解决方案”(类似这样的内容),那不是很棒吗? )?

为此,插件应该配置某种基本目录。从那里,它需要创建所有可用解决方案文件和所包含项目的集合。当右键单击引用时,它应该扫描项目文件以获取相应的输出,如果找到,则显示用于直接打开相应解决方案的菜单项(也许也可以预取此信息)。

嗯...你们有人已经创建了这样的插件吗?有谁知道有一个插件已经做了类似的事情吗?

如果这些问题都没有回答“是”: 任何人都可以向我指出如何根据设定的先决条件扩展解决方案资源管理器上下文菜单的方向吗?

Imagine a folder structure that contains more than 200 solution files for projects that all belong to one software. Most of them generate shared libraries that are referenced in other projects that are contained in own solutions.

Wouldn't it be wonderful if there was a possibility of right clicking such a referenced assembly in the solution explorer and then having a context menu item such as "Open solution" and "Open solution in a new Visual Studio instance" (something like this)?

For this to work, the addin should be configured with some sort of base directory. From there it needs to create a collection of all available solution files and the contained projects. When a reference is right clicked, it should scan the project files for the corresponding output and - if found - present the menu items for directly opening the corresponding solution (maybe this information could be prefetched, too).

Well... did anyone of you already create such an addin? Does anyone happen to know an addin that already does something like this?

If neither of those questions is answered with "yes":
Can anyone point me to a direction of how to extend the solution explorers context menu based on set preconditions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫嚣ゝ 2024-09-06 04:36:55

Afaik 你无法使用 VS MEF 扩展来做到这一点,但使用 VS Add-in 来做到这一点可能并不那么困难。

  1. 使用MZTools示例/模板来编写将添加您的部分菜单到相应的命令栏(这是上下文菜单弹出窗口,其中包括解决方案资源管理器的命令)。我所关注的是 SolutionProject。我想还有一个名为 Reference 的 commandBar。在以下代码中,ApplicationObject 的类型为 EnvDTE 以下是一些用于搜索所需命令栏的代码:

     private void IterateAllCommandBars( )
    {
        var commandBars =(CommandBars)ApplicationObject.CommandBars;
        调试.缩进( );
        foreach(commandBars 中的 CommandBar commandBar)
        {
            调试.WriteLine(commandBar.Name);
        }
        调试.取消缩进( );
    }
    
  2. 加载扩展程序时(通常在 OnStartupComplete 中))然后,您可以查找先决条件并设置一个将引用映射到解决方案路径的字典。

  3. 使用在外接程序上调用的 QueryStatus 调用来根据选择的引用(如果有)启用/禁用菜单。例如,我获取选定的项目(如果有):

    私有静态项目 GetProject(DTE applicationObject)
    {
        if (applicationObject.Solution==null||applicationObject.Solution.Projects==null||applicationObject.Solution.Projects.Count<1)
            返回空值;
        if (applicationObject.SelectedItems.Count==1&&applicationObject.SelectedItems.Item(1).Project!=null)
            返回 applicationObject.SelectedItems.Item(1).Project;
        返回空值;
    }
    
  4. 当用户单击有效选项时执行您想要调用的命令。我不确定如何或是否可以让它在现有 VS 实例中打开解决方案,但在新的 VS 中打开会很容易。 Process.Start(ProjectFullPath); 或者可能是 SolutionFullPath。

Afaik you can't do this with a VS MEF extension, but it's probably not all that difficult to do with a VS Add-in.

  1. Use MZTools samples/templates to write the part that would add your menu to the appropriate command bar (this is the context menu pop-up which includes the Solution Explorer's commands). The ones I hooked into were Solution and Project. I imagine there is also a commandBar called Reference. In the following code ApplicationObject is of type EnvDTE Here's some code to search for the command bar you need:

        private void IterateAllCommandBars( )
    {
        var commandBars =(CommandBars)ApplicationObject.CommandBars;
        Debug.Indent( );
        foreach (CommandBar commandBar in commandBars)
        {
            Debug.WriteLine(commandBar.Name);
        }
        Debug.Unindent( );
    }
    
  2. When your extension is loaded (typically in OnStartupComplete) you can then look for your preconditions and set up a dictionary that maps reference to solution path.

  3. Use the QueryStatus call that is invoked on your add in to enable/disable the menu based on which reference is selected if any. For Example I get the selected project if any:

    private static Project GetProject(DTE applicationObject)
    {
        if (applicationObject.Solution==null||applicationObject.Solution.Projects==null||applicationObject.Solution.Projects.Count<1)
            return null;
        if (applicationObject.SelectedItems.Count==1&&applicationObject.SelectedItems.Item(1).Project!=null)
            return applicationObject.SelectedItems.Item(1).Project;
        return null;
    }
    
  4. Execute the command you want to invoke when the user clicks a valid option. I'm not sure how or if you could have it open the solution in the existing VS instance, but opening in a new VS would be easy. Process.Start(ProjectFullPath); or that could be SolutionFullPath.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文