Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio加载项-将命令添加到文件->;新菜单_C#_Visual Studio_Visual Studio Addins - Fatal编程技术网

C# Visual Studio加载项-将命令添加到文件->;新菜单

C# Visual Studio加载项-将命令添加到文件->;新菜单,c#,visual-studio,visual-studio-addins,C#,Visual Studio,Visual Studio Addins,我在“工具”菜单中有一个菜单项,但它需要进入“文件”->“新建”菜单,然而,即使在预生成的visual studio代码中将“工具”更改为“文件”,也不会给出预期的结果 您还需要更改eventlistner代码。检查代码顶部自动生成的代码段。您还需要更改eventlistner代码。检查代码顶部自动生成的代码段。以下代码(不是防弹的!)在Addin OnConnection方法中对我来说很好: _applicationObject = (DTE2)application; _addInInsta

我在“工具”菜单中有一个菜单项,但它需要进入“文件”->“新建”菜单,然而,即使在预生成的visual studio代码中将“工具”更改为“文件”,也不会给出预期的结果

您还需要更改eventlistner代码。检查代码顶部自动生成的代码段。

您还需要更改eventlistner代码。检查代码顶部自动生成的代码段。

以下代码(不是防弹的!)在Addin OnConnection方法中对我来说很好:

_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_UISetup)
{
    object[] contextGUIDS = new object[] { };
    Commands2 commands = (Commands2)_applicationObject.Commands;

    CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;
    CommandBar menuBarCommandBar = commandBars["MenuBar"];

    CommandBarPopup filePopup = menuBarCommandBar.Controls["File"] as CommandBarPopup;
    CommandBarPopup newPopup = filePopup.CommandBar.Controls["New"] as CommandBarPopup;

    Command command = commands.AddNamedCommand2(_addInInstance, "MyAddin1", "MyAddin1", 
        "Executes the command for MyAddin1", true, 59, ref contextGUIDS, 
        (int)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled),
        (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

    if (command != null && newPopup != null)
    {
        command.AddControl(newPopup.CommandBar, 1);
    }
}
以下代码(不是防弹的!)在Addin OnConnection方法中适用于我:

_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
if (connectMode == ext_ConnectMode.ext_cm_UISetup)
{
    object[] contextGUIDS = new object[] { };
    Commands2 commands = (Commands2)_applicationObject.Commands;

    CommandBars commandBars = (CommandBars)_applicationObject.CommandBars;
    CommandBar menuBarCommandBar = commandBars["MenuBar"];

    CommandBarPopup filePopup = menuBarCommandBar.Controls["File"] as CommandBarPopup;
    CommandBarPopup newPopup = filePopup.CommandBar.Controls["New"] as CommandBarPopup;

    Command command = commands.AddNamedCommand2(_addInInstance, "MyAddin1", "MyAddin1", 
        "Executes the command for MyAddin1", true, 59, ref contextGUIDS, 
        (int)(vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled),
        (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);

    if (command != null && newPopup != null)
    {
        command.AddControl(newPopup.CommandBar, 1);
    }
}

您是否尝试过在命令行的.AddIn.Name中运行devenv.exe/resetaddin(例如devenv.exe/resetaddin MyAddin1.Connect)?

您是否尝试过在命令行的.AddIn.Name中运行devenv.exe/resetaddin(例如devenv.exe/resetaddin MyAddin1.Connect)?

代码“看起来”应该可以工作,但将代码放在我的项目中没有任何作用。我仍然在工具菜单中使用我的命令,我甚至可以通过我设置的断点,外观没有任何变化。代码“看起来”应该可以工作,但将代码放在我的项目中没有任何作用。我仍然在工具菜单中使用我的命令,我甚至可以通过我设置的断点,外观没有任何变化