3

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

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

4

1 回答 1

0

您可以从加载项将按钮添加到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文件来添加命令和菜单项。

于 2013-12-25T13:32:19.133 回答