VS加载项:在Web应用程序上添加上下文按钮

时间:2009-06-16 16:55:54

标签: visual-studio

我正在搞乱Visual Studio(2008)加载项。我希望能够为所有Web应用程序上下文菜单添加一个按钮(将根据Web部署工具中的共享存档为该网站设置IIS)。

我已经能够在项目上下文菜单中添加上下文项:

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)

{     applicationObject =(DTE2)应用程序;     addInInstance =(AddIn)addInInst;

if (connectMode == ext_ConnectMode.ext_cm_UISetup) {
    var contextGuids = new Object[] {};
    var iisSetupCommand = applicationObject.Commands.AddNamedCommand(
        addInInstance,
        CommandNameSetupIis,
        "Setup IIS",
        "Create the bindings in IIS for the website. Requires an IIS folder in the project root with the archive xml files for the website.",
        true,
        52,
        ref contextGuids,
        (int) vsCommandStatus.vsCommandStatusSupported + (int) vsCommandStatus.vsCommandStatusEnabled
        );

    var commandBars = (CommandBars) applicationObject.CommandBars;
    var projectMenu = commandBars["Project"];
    iisSetupCommand.AddControl(projectMenu, projectMenu.Controls.Count + 1);
}

}

这有效,但我无法进一步发展。

问题1是点击时按钮消失。

问题2是我不知道如何只显示Web应用程序项目的按钮。

问题3是我需要编写代码来获取iis存档,当前项目目录路径和项目名称以创建IIS绑定,然后使用这些设置运行Web部署工具。

这个加载项非常钝。我尽可能多地搜索并阅读大部分(可怕的)msdn文档。我发现的最佳信息是:http://dotnetslackers.com/articles/vs_addin/Lessons_learned_from_Copy_to_Html_Add_in.aspx

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

问题1:覆盖QueryStatus并将状态设置为vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled

问题2:我认为这不可行。可以获取项目类型,但只有在单击按钮后才会显示(一旦单击按钮,QueryStatus似乎只会触发)。

问题3:项目路径可通过connect.ApplicationObject.ActiveSolutionProjects获得。