{"id":2783,"date":"2009-12-07T08:05:00","date_gmt":"2009-12-07T08:05:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/visualstudio\/2009\/12\/07\/bootstrapping-of-vs-packages-and-vsix-extensions-in-vs2010\/"},"modified":"2019-02-14T15:42:03","modified_gmt":"2019-02-14T23:42:03","slug":"bootstrapping-of-vs-packages-and-vsix-extensions-in-vs2010","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/visualstudio\/bootstrapping-of-vs-packages-and-vsix-extensions-in-vs2010\/","title":{"rendered":"Bootstrapping of VS packages and VSIX extensions in VS2010"},"content":{"rendered":"<p><strong><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/dmitry_4.png\"><img decoding=\"async\" title=\"dmitry\" border=\"0\" alt=\"dmitry\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2009\/12\/dmitry_thumb_1.png\" width=\"82\" height=\"88\"><\/a> Dmitry Goncharenko: <\/strong>Developer, Visual Studio Platform<\/p>\n<p><b>Short bio<\/b>: Dmitry has been at Microsoft for about 10 years working on several areas of Visual Studio. For Visual Studio 2010, he helped to design and implement PkgDef management, VSIX technologies, and hosting of MEF components.<\/p>\n<p>Visual Studio 2010 uses two technologies to make it much <i>simpler<\/i> to deploy VS extensions:<\/p>\n<ol>\n<li>VS Packages don\u2019t need to write registration information directly to the registry. They can provide all their registration information in <a href=\"http:\/\/blogs.msdn.com\/aaronmar\/archive\/2009\/06\/05\/pkgdef-and-the-experimental-instance-in-vs-2010.aspx\">PkgDef<\/a> files, instead. <\/li>\n<li><a href=\"http:\/\/blogs.msdn.com\/quanto\/archive\/2009\/05\/26\/what-is-a-vsix.aspx\">VSIX<\/a> is the new deployment model available for deploying VS 2010 extensions. It is fully integrated into the IDE and provides a simple model for publishing extensions to the <a href=\"http:\/\/visualstudiogallery.msdn.microsoft.com\/en-us\/\">Visual Studio Gallery<\/a>.<\/li>\n<\/ol>\n<p>Given different (previously supported and new) types of extensions available in VS2010 it might be not clear how they are being discovered and bootstrapped by the IDE. This post is an attempt to shed some light onto this area of VS Platform.<\/p>\n<p>The Visual Studio process is launched by executing <strong>devenv.exe<\/strong>, which is located in &lt;VsInstallRootFolder&gt;Common7IDE. After doing some critical steps like command line parsing and Watson integration initialization (the technology managing crash\/hang dumps), devenv.exe initializes the <b>PkgDef Management<\/b> logic. [Note that Express VS SKUs are launched using different executables but internally they have a very similar logic to devenv.exe.]<\/p>\n<p>PkgDef Management draws its initialization parameters from the file <b>devenv.pkgdef<\/b>, which is located next to devenv.exe (also called the \u201c<b>Master PkgDef<\/b>\u201d). This file defines the locations where VS should be looking for other PkgDef files and installed VSIX extensions. <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/image_2.png\"><img decoding=\"async\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2009\/12\/image_thumb-2.png\" width=\"417\" height=\"309\"><\/a> <\/p>\n<p>Here is the content of a sample devenv.pkgdef file:<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/image4.png\"><img decoding=\"async\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2009\/12\/image4_thumb.png\" width=\"930\" height=\"155\"><\/a> <\/p>\n<p>The table below describes some variables that will typically be in the Master PkgDef file:<\/p>\n<table border=\"1\" cellSpacing=\"0\" cellPadding=\"0\" width=\"830\">\n<tbody>\n<tr>\n<td vAlign=\"top\" width=\"184\">\n<p><b>Variable<\/b><\/p>\n<\/td>\n<td vAlign=\"top\" width=\"644\">\n<p><b>Description<\/b><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"top\" width=\"184\">\n<p>RegistryRoot<\/p>\n<\/td>\n<td vAlign=\"top\" width=\"644\">\n<p>The root registry location under HKEY_CURRENT_USER where user settings and configuration cache are stored.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"top\" width=\"184\">\n<p>PkgDefSearchPath<\/p>\n<\/td>\n<td vAlign=\"top\" width=\"644\">\n<p>The list of folders where to search for PkgDef files. The list can also include specific PkgDef files.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"top\" width=\"184\">\n<p>ApplicationExtensionsFolder<\/p>\n<\/td>\n<td vAlign=\"top\" width=\"644\">\n<p>The root folder under which machine wide VSIXs are deployed.<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td vAlign=\"top\" width=\"184\">\n<p>UserExtensionsRootFolder<\/p>\n<\/td>\n<td vAlign=\"top\" width=\"644\">\n<p>The root folder under which user specific VSIXs are deployed.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>The main job of PkgDef Management is to locate, load PkgDef files and merge them with the rest the configuration data that is located under HKLMSOFTWAREMicrosoftVisualStudio10.0 (or <a href=\"http:\/\/social.msdn.microsoft.com\/Forums\/en-US\/vsxprerelease\/thread\/3d38070a-2b61-489d-b3f9-c1c9595176d0\">HKLMWow6432NodeSoftwareMicrosoftVisualStudio10.0<\/a> on 64-bit OSs). The folders listed in the <b>PkgDefSearchPath <\/b>are scanned recursively and PkgDef files found there are loaded. PkgDef Management then scans recursively starting from extension folders under <b>UserExtensionsRootFolder <\/b>and loads only those PkgDef files that belong to extensions marked as \u201cEnabled\u201d in the <strong>Extension Manager<\/strong> dialog.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/image_8.png\"><img decoding=\"async\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2009\/12\/image_thumb_3-1.png\" width=\"560\" height=\"145\"><\/a> <\/p>\n<p>Once all Visual Studio configuration data is loaded and merged, it is then cached under HKCUSoftwareMicrosoftVisualStudio10.0_Config registry root. Since this cache can be updated at any moment <a href=\"http:\/\/blogs.msdn.com\/aaronmar\/archive\/2009\/11\/06\/all-your-regkeys-are-belong-to-us.aspx\">don\u2019t ever edit it<\/a>. If you need to modify the configuration data (for example to register your VS package) add a PkgDef file instead to your extension. [Don\u2019t ever hardcode VS registry paths into your code. Use <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.visualstudio.shell.settings.shellsettingsmanager(VS.100).aspx\">ShellSettingsManager<\/a> class from Microsoft.VisualStudio.Shell.10.0.dll to work with VS settings and configuration data.]<\/p>\n<p>Once the configuration data is ready, the rest of Visual Studio can use it to initialize its core services and build the UI (main frame, menus, command bars, tool windows, etc.) This step deserves its own discussion but it is beyond of the scope of this article. The very last step before the IDE starts receiving user input is to initialize the main message loop. <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.visualstudio.ole.interop.solecomponentmanager.aspx\">SOleComponentManager<\/a> service is responsible for managing VS message pump and it as well deserves its own blog post (or even few).<\/p>\n<p>So, how does all this tie to the Extension Manager and VSIX extensions? At some point <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.visualstudio.extensionmanager.svsextensionmanager(VS.100).aspx\">SVsExtensionManager<\/a> service will be invoked (which depending on the scenario could be before or after VS became responsive). The service recursively scans below the ApplicationExtensionsFolder folder defined in the Master PkgDef file for <strong>extension.vsixmanifest<\/strong> files. All found VSIX extensions under ApplicationExtensionsFolder become available to VS. <\/p>\n<p>UserExtensionsRootFolder in the Master PkgDef file specifies the path under which per-user VSIXs are installed (via the the Extension Manager dialog or by the Standalone VSIX installer). Extensions (VSIXs) installed into these \u201cper user\u201d folders are only loaded if the following criteria (as of the Beta 2 release) are met:<\/p>\n<ul>\n<li>They are loaded only if the user is not an administrator on the machine, or <\/li>\n<li>The highlighted below option is checked in Tools | Options. <\/li>\n<\/ul>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/4\/2019\/06\/image_6.png\"><img decoding=\"async\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-content\/uploads\/sites\/4\/2009\/12\/image_thumb_2-1.png\" width=\"829\" height=\"210\"><\/a> <\/p>\n<p>Only the VSIXs that are marked as \u201cEnabled\u201d in the Extension Manager dialog are considered by the service and made available to VS. <\/p>\n<p>After a VSIX is enabled or disabled, VS might need to be restarted for this change to take an effect. This is true for VSIXs containing PkgDef files because, as it is described above, any changes to PkgDef files are processed only during the startup of VS.<\/p>\n<p>Finally a short list of troubleshooting options for VS startup issues:<\/p>\n<ul>\n<li>Run <strong>devenv.exe \/log [&lt;optional log file path&gt;]<\/strong> for generating a detailed log of VS startup activities. If the log file path is not specified then by default the log is written into %APPDATA%MicrosoftVisualStudio10.0ActivityLog.xml. Open the log in a web browser and look for any \u201cyellow\u201d or \u201cred\u201d entries to quickly locate the problem spots. <\/li>\n<li>If VS fails to start or some feature becomes broken after installing a new VSIX, then run <strong>devenv.exe \/SafeMode<\/strong> to re-launch VS with only the \u201csafe\u201d set of extensions enabled. Then go to the Extension Manager dialog and disable the extensions that have been recently installed. <\/li>\n<li>If it is not clear which VSIX caused the problem, run <strong>devenv.exe <\/strong>\/<strong>ResetUserData<\/strong> in order to bring VS to the known initial state (as if it has been just installed). <\/li>\n<\/ul>\n<p>Dmitry.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dmitry Goncharenko: Developer, Visual Studio Platform Short bio: Dmitry has been at Microsoft for about 10 years working on several areas of Visual Studio. For Visual Studio 2010, he helped to design and implement PkgDef management, VSIX technologies, and hosting of MEF components. Visual Studio 2010 uses two technologies to make it much simpler to [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":255385,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[155],"tags":[185],"class_list":["post-2783","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-visual-studio","tag-node-js"],"acf":[],"blog_post_summary":"<p>Dmitry Goncharenko: Developer, Visual Studio Platform Short bio: Dmitry has been at Microsoft for about 10 years working on several areas of Visual Studio. For Visual Studio 2010, he helped to design and implement PkgDef management, VSIX technologies, and hosting of MEF components. Visual Studio 2010 uses two technologies to make it much simpler to [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/2783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/comments?post=2783"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/posts\/2783\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media\/255385"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/media?parent=2783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/categories?post=2783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/visualstudio\/wp-json\/wp\/v2\/tags?post=2783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}