{"id":2157,"date":"2019-07-11T11:27:08","date_gmt":"2019-07-11T15:27:08","guid":{"rendered":"http:\/\/codinggorilla.com\/?p=2157"},"modified":"2019-07-23T06:13:05","modified_gmt":"2019-07-23T10:13:05","slug":"adding-an-extension-menu-underneath-the-extensions-menu-item-in-visual-studio-2019","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2019\/07\/11\/adding-an-extension-menu-underneath-the-extensions-menu-item-in-visual-studio-2019\/","title":{"rendered":"Porting extensions to Visual Studio 2019"},"content":{"rendered":"\n<p>I was recently was trying to use <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/kaby76\/AntlrVSIX\" target=\"_blank\">my Visual Studio extension for Antlr<\/a> in Visual Studio 2019, when I found that it just isn&#8217;t working anymore. In fact, I couldn&#8217;t even install the extension because it wouldn&#8217;t even show up in the search for the plug-in. In fact, there weren&#8217;t any extensions available for &#8220;Antlr&#8221; for Visual Studio 2019! I guess I hadn&#8217;t ported the add-in to VS 2019, so I decided to work on that.<\/p>\n\n\n\n<!--more-->\n\n\n\n<h2>Getting it to install in VS 2019<\/h2>\n\n\n\n<p><a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/how-to-upgrade-extensions-to-support-visual-studio-2019\/\">Mads Kristensen says that you only need to change a few things to get an extension that worked in Visual Studio 2017 to work with Visual Studio 2019.<\/a> That&#8217;s simply not true in my case. But, Kristensen&#8217;s suggested fixes do take care of the problem of adding the extension to Visual Studio 2019 when the .vsix file is double-clicked. And, it will likely take care of the problem of it not showing up when searching for the extension in VS 2019.<\/p>\n\n\n\n<h2>Top-level menus have changed<\/h2>\n\n\n\n<p>But, the main problem is an organizational issue. Most extension that I use in VS 2019 have the UI for the extension now appear under the <strong>Extensions<\/strong> menu. It is not clear how to do that. The <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/extensibility\/adding-a-menu-to-the-visual-studio-menu-bar?view=vs-2019\" target=\"_blank\">documentation for adding a menu to the Visual Studio menu bar<\/a> says little about &#8220;top-level menus&#8221;, except this &#8220;Note: In VS 2019, top-level menus contributed by extensions are placed under the&nbsp;<strong>Extensions<\/strong>&nbsp;menu.&#8221; This, of course, means absolutely nothing because it&#8217;s never explained anywhere how to create a top-level menu! In fact, there are only a handful of discussions found via <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/www.google.com\/search?q=IDM_VS_TOOL_MAINMENU\" target=\"_blank\">Google Search of IDM_VS_TOOL_MAINMENU<\/a>, which is a key implementation detail never described.<\/p>\n\n\n\n<p>Starting with the <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/github.com\/microsoft\/VSSDK-Extensibility-Samples\/tree\/master\/Menu_And_Commands\" target=\"_blank\">VSSDK Extensibility Samples, Menu and Commands<\/a>, the code to add a menu to <strong>Tools<\/strong> menu is right there and works. However, modifying the .vsct file for the parent menu is not apparent.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Parent guid=\"guidSHLMainMenu\" id=\"IDM_VS_MENU_TOOLS\"\/><\/code><\/pre>\n\n\n\n<p>Replacing IDM_VS_MENU_TOOLS with  IDM_VS_MENU_EXTENSIONS results in a compiler error:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>...\\VSSDK-Extensibility-Samples\\Menu_And_Commands\\C#\\PkgCmd.vsct(112,40):\nerror VSCT1103: Undefined 'Parent\/@id' attribute 'IDM_VS_MENU_EXTENSIONS'\nin a &lt;Group> element<\/code><\/pre>\n\n\n\n<p>Although IDM_VS_MENU_EXTENSIONS is listed as a valid menu in the <a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/docs.microsoft.com\/en-us\/visualstudio\/extensibility\/internals\/guids-and-ids-of-visual-studio-menus?view=vs-2019\" target=\"_blank\">documentation<\/a>, I cannot use the constant like the other IDM_VS_MENU_&#8230; ID&#8217;s.<\/p>\n\n\n\n<p>The solution to adding the menu group to the EXTENSIONS menu is to use  IDM_VS_TOOL_MAINMENU.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Parent guid=\"guidSHLMainMenu\" id=\"IDM_VS_TOOL_MAINMENU\"\/><\/code><\/pre>\n\n\n\n<h2>Managed Extensibility Framework (MEF)<\/h2>\n\n\n\n<p>It seems that MEF (aka, unmanageable unextensibility fuck-up) has changed and no longer loads my extension. I&#8217;m not exactly sure how to debug this because the <a href=\"https:\/\/github.com\/MicrosoftArchive\/mef\/releases\/tag\/4.0\">MEF Analysis Tool (MEFX) no longer exists<\/a>. But, it isn&#8217;t clear how you use the tool as it&#8217;s pretty cryptic. But, it does point to some portions that I can comment out.<\/p>\n\n\n\n<p>Long story short: It turns out I got a little &#8220;cut&#8221; happy with source.extension.manifest. If your extension uses MEF, do not delete the MEF reference.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;Assets>\n    &lt;Asset Type=\"Microsoft.VisualStudio.MefComponent\"\n       d:Source=\"Project\" d:ProjectName=\"%CurrentProject%\" \n           Path=\"|%CurrentProject%|\" \/>\n&lt;\/Assets><\/code><\/pre>\n\n\n\n<h2>Migrating packages.config to PackageReference<\/h2>\n\n\n\n<p>In VS 2019, <a href=\"https:\/\/docs.microsoft.com\/en-us\/nuget\/reference\/migrate-packages-config-to-package-reference#package-compatibility-issues\">there is now an option to convert the packages.config to package references within the .csproj file<\/a>. To do that, I had to upgrade to Net 4.7.2, then navigate to References in the Solution Manager and right-click. It then offered an option to do the migration. Note, if I removed the app.config file, or didn&#8217;t do the upgrade to Net 4.7.2, the option to migrate didn&#8217;t appear. Afterward, I could then remove the app.config file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was recently was trying to use my Visual Studio extension for Antlr in Visual Studio 2019, when I found that it just isn&#8217;t working anymore. In fact, I couldn&#8217;t even install the extension because it wouldn&#8217;t even show up in the search for the plug-in. In fact, there weren&#8217;t any extensions available for &#8220;Antlr&#8221; &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/165.227.223.229\/index.php\/2019\/07\/11\/adding-an-extension-menu-underneath-the-extensions-menu-item-in-visual-studio-2019\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Porting extensions to Visual Studio 2019&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/2157"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=2157"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/2157\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=2157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=2157"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=2157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}