title: How to have a VSTO Ribbon and Context Menu at the same time?
body: <p><strong>EDIT: The posters answer is correct except for it should read xmlns="http://schemas.microsoft.com/office/2009/07/customui" for the include. As a side effect the ribbon and context menu defined in an XML file will not work in Office 2007. If you need to add a context menu in 2007, use the now deprecated, and a context menu within the Outlook 2007 message window is NOT POSSIBLE.</strong>   </p>
  
  <pre><code>this.Application.ItemContextMenuDisplay += new Microsoft.Office.Interop.Outlook.ApplicationEvents_11_ItemContextMenuDisplayEventHandler(Application_ItemContextMenuDisplay);
  </code></pre>
  
  <p>I've created both a Ribbon and a Context menu, but I do not know how to deploy both of them at the same time. </p>
  
  <p>My Ribbon XML looks something like this: </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;customUI onLoad="Ribbon_Load" xmlns="http://schemas.microsoft.com/office/2006/01/customui"&gt;
  
  &lt;ribbon&gt;
  
  &lt;tabs&gt;
  
    &lt;tab id="testTab" label="Test Label"&gt;
  
      &lt;group id="testGroup" label="test"&gt;
  
        &lt;button id="testButton" onAction="testAction" label="Test" size="large" 
  
            getImage ="GetCustomImage" screentip="Test Ribbon Functionality."/&gt;         
  
      &lt;/group&gt;      
  
    &lt;/tab&gt;
  
   &lt;/tabs&gt;
  
  &lt;/ribbon&gt;
  
  &lt;/customUI&gt;
  </code></pre>
  
  <p>Ribbon.cs has</p>
  
  <pre><code>public string GetCustomUI(string ribbonID)
  
  {
  
    String ui = null;
  
    // Examine the ribbonID to see if the current item
  
    // is a Mail inspector.
  
    if (ribbonID == "Microsoft.Outlook.Mail.Read" ||
  
      ribbonID == "Microsoft.Outlook.Mail.Compose")
  
    {
  
      // Retrieve the customized Ribbon XML.
  
      ui = GetResourceText("WDCrypt2.Ribbon.xml") ;
  
  
  
    }
  
    return ui;
  
  }
  </code></pre>
  
  <p>ContextMenu XML looks like (from a tutorial)</p>
  
  <pre><code>&lt;customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui"&gt;
  
   &lt;contextMenus&gt;
  
    &lt;contextMenu idMso="ContextMenuText"&gt;
  
     &lt;button idMso="FontDialog" visible="false" /&gt;
  
     &lt;toggleButton id="MyToggle" label="My Toggle Button" /&gt;
  
     &lt;button id="MyButton" label="My Button" insertBeforeMso="HyperlinkInsert" onAction="GetButtonID" /&gt;
  
     &lt;menuSeparator id="MySeparator" /&gt;
  
     &lt;menu id="MySubMenu" label="My Submenu" &gt;
  
      &lt;button id="MyButton2" label="Button on submenu" /&gt;
  
     &lt;/menu&gt;
  
     &lt;gallery id="galleryOne" label="My Gallery"&gt;
  
      &lt;item id="item1" imageMso="HappyFace" /&gt;
  
      &lt;item id="item2" imageMso="HappyFace" /&gt;
  
      &lt;item id="item3" imageMso="HappyFace" /&gt;
  
      &lt;item id="item4" imageMso="HappyFace" /&gt;
  
     &lt;/gallery&gt;
  
     &lt;dynamicMenu id="MyDynamicMenu" label= "My Dynamic Menu" getContent="GetMyContent" /&gt;
  
    &lt;/contextMenu&gt;
  
   &lt;/contextMenus&gt;
  
  &lt;/customUI&gt;
  </code></pre>
  
  <p>With its cs file which looks like:</p>
  
  <pre><code>private Office.IRibbonUI ribbon;
  
  public Ribbon2()
  {
  }
  
  #region IRibbonExtensibility Members
  
  public string GetCustomUI(string ribbonID)
  {
    return GetResourceText("WDCrypt2.Ribbon2.xml");
  }
  </code></pre>
  
  <p>The problem is to use either in my Addin Class I must:</p>
  
  <pre><code>protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
  {
  
    return new Ribbon();
  
  }
  </code></pre>
  
  <p>OR</p>
  
  <pre><code>protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
  {
  
    return new Ribbon2(); //The Context Menu
  
  }
  </code></pre>
  
  <p>But I cannot do both. How do I get both the context menu and the ribbon at the same time?</p>
  
  <p><strong>Edit:</strong> I would also like to refrain from using Application.ItemContextMenuDisplay, as this is officially deprecated by the API. </p>