【问题标题】:Is it possible to add solution-specific tools to Visual Studio 2012是否可以将特定于解决方案的工具添加到 Visual Studio 2012
【发布时间】:2012-12-18 13:39:51
【问题描述】:

您能否对 VS2012 中的 .SLN/.CSPROJ 文件做一些事情,这样当您在解决方案资源管理器中右键单击解决方案/项目时,上下文菜单上会出现一个运行您指定的工具的新项目?

我知道您可以将自定义条目添加到“工具”菜单,但在这种情况下,这些工具是特定于该特定解决方案的。

【问题讨论】:

    标签: visual-studio-2012 extensibility


    【解决方案1】:

    您可以通过插件将按钮添加到Solution 上下文菜单,如下所示:

    Microsoft.VisualStudio.CommandBars.CommandBar menuBarCommandBar = ((Microsoft.VisualStudio.CommandBars.CommandBars)_applicationObject.CommandBars)["Solution"];
    
    try
    {
        //Add a command to the Commands collection:
        Command command = commands.AddNamedCommand2(_addInInstance, "MyAddinMenuBar", "MyAddinMenuBar", "Executes the command for MyAddinMenuBar", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);
    
        //Add a control for the command to the solution context menu:
        if (command != null)
        {
            command.AddControl(menuBarCommandBar, 1);
        }
    }
    catch (System.ArgumentException)
    {
        //  safely ignore the exception.
    }
    

    不同解决方案的工具规范应由您的插件在内部处理。您可以提取解决方案的完整路径(来自_applicationObject.Solution.FullName)以及包含的项目的属性(来自_applicationObject.Solution.Projects)。

    如果您使用的是VSPackage,您应该定义一个vsct 文件来添加命令和菜单项。

    【讨论】:

    • 我可以在解决方案中添加插件吗?也就是说,把它放在源代码管理中,这样无论谁签出副本并打开解决方案,也会自动安装加载项?
    • 如果您将源代码放入您的解决方案中,那么我认为您的加载项将无法正确部署。您必须将 .AddIn 文件复制到 ..\Documents\Visual Studio 20[XY]\Addins 文件夹,并设置 元素以使其工作。也有共享的 .AddIn 容器,但是必须将程序集放在全局路径上。
    • 对于部署,我建议使用 WiX 工具集(作为在线扩展提供),您也可以尝试将您的加载项用作 Solution Add-In
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-07
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 2018-08-03
    • 1970-01-01
    相关资源
    最近更新 更多