How to tell Visual Studio to load only the extension I'm currently debugging (and nothing more)?

2k views Asked by At

I've read How to debug Visual Studio extensions.

As a fact, VS2013 sets up extension project automatically for that.

I have a number of extensions (also add-ons and so on: Resharper, OzCode, GitExtensions..). All of them have slow loading times, obviously.

Is there a way, to run extension debug session on a "clean" Visual Studio? Just vanilla: nothing installed except extension under debug.

EDIT: just wanted to clear a little: resharper is not loading itself in experimental hive, some other extensions are, though

2

There are 2 answers

1
Igal Tabachnik On BEST ANSWER

Welcome to the wonderful world of Visual Studio extensibility!

In order to prepare your environment for any serious extension development, you will need to do several things, involving moving installed extensions around and changing Visual Studio configuration files. Below is a brief explanation about the process:

Prerequisites

Before going further, here is the necessary "knowledge" every extension developer needs to posses:

  1. What's a PkgDef? - important information about the Visual Studio package format
  2. VSIX discovery - how Visual Studio discovers and loads VSIX packages
  3. Custom hives - running multiple Visual Studio profiles

First two articles are fairly old, but they still hold crucial information. In Visual Studio 2012 and above, the VSIX discovery process was changed slightly, so that Visual Studio does not rebuild the package cache on every startup. To rebuild the package cache, run from an elevated Developer Command Prompt for the specific version of Visual Studio:

devenv /Setup

or use the undocumented command:

devenv /updateconfiguration

which does not require elevation, but rather it tells Visual Studio to refresh its package cache on the next restart.

Most of the time, all extensions you install (e.g. ReSharper, OzCode, other extensions from the Gallery) will by default install themselves per-machine, by placing themselves in %VSINSTALLDIR%\Common7\IDE\Extensions. Remember that the default pkgdef search path (as defined by devenv.pkgdef) is:

"PkgDefSearchPath" = $ApplicationExtensionsFolder$;$RootFolder$\Common7\IDE\CommonExtensions;$RootFolder$\Common7\IDE\devenv.admin.pkgdef;"

This means, whenever you start Visual Studio in any hive, it will first look at the per-machine location for the installed extension, and load them up. Whenever you create a new VSIX project, the default setting is to launch it in the /RootSuffix Exp hive, which will still attempt to load the per-machine extensions first.

Which brings me to answering your question.

In order to prevent extensions from loading in your other hives, they need to be moved to a per-hive location: %LOCALAPPDATA%\Microsoft\VisualStudio\<vsVersion><hive>\Extensions. Later versions of Visual Studio (2013 and above) allow you to do that from the Visual Studio settings, but you need to run Visual Studio as an administrator for this to work:

However, instead of running as administrator, it's possible to modify the default package search path, to include the per-user location in it. Then, move the extensions manually to that new location.

Here's what you do:

  1. Open an elevated Notepad(++) (right-click - Run as Administrator)
  2. Open the file devenv.pkgdef, located in the Visual Studio installation directory, e.g. C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.pkgdef.
  3. In the PkgDefSearchPath, add $AppDataLocalFolder$\Extensions; as the first value, before $ApplicationExtensionsFolder$, so it looks like this:
  4. Save the file

Now you can go to the Common7\IDE\Extensions folder, and move the directories of those extensions to the per-user location. So for example, if you wanted to move NCrunch in Visual Studio 2015, take the entire folder Remco Software, and move it to %LOCALAPPDATA%\Microsoft\VisualStudio\14.0\Extensions.

Finally, refresh Visual Studio package cache, by running one of the two commands above. When you Visual Studio, it will still load the extensions, but whenever you run another hive (Exp or any other), those per-user extensions won't be loaded.

It seems like an involved process, but you only need to do it once, and just for the "huge" extensions (mainly, ReSharper). Note that since v9, ReSharper installs itself per-hive, so you don't even have to do this anymore!

Sorry for the long explanation, hope that helps!

0
Eli Dagan On

I think this answer can help you. "Run Visual studio vs package in custom Hive (not Exp)"