Logo
HOWTO: Reset a Visual Studio add-in

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: February 2006   Microsoft Visual Studio .NET 2003
Updated: March 2013   Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010
      Microsoft Visual Studio 2012
Introduction

This article explains how to reset the commands and user interface of a Visual Studio .NET add-in.

More Information

An add-in typically can create a command:

  • Using the ext_cm_UISetup flag in the connectMode parameter of the OnConnection method, and this happens only once in the whole lifetime of the add-in (more on this later).
  • When loaded: the add-in can check if the command exists in the DTE.Commands collection, and create it if it doesn't exist. In this scenario the add-in doesn't use the ext_cm_UISetup flag of the OnConnection method.

For more information, see: HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in

An add-in that uses ext_cm_UISetup flag to create the commands uses a CommandPreload = 1 registry entry value (for add-ins using Registry registration) or XML entry (for Visual Studio 2005 or higher add-ins using XML registration). The add-in wizard creates this value when you check the checkbox "Yes, create a "Tools" menu item. By default this will cause the Add-in to load when the button is clicked unless the Add-in is set to load on startup of the host application." in one of the steps of the wizard.

The CommandPreload = 1 value indicates Visual Studio that the add-in needs to use the ext_cm_UISetup flag to create its commands. That command creation should happen only once, and therefore Visual Studio .NET needs to know whether the flag has been used or not. For this purpose, it can use different locations to store if that flag has been already used:

  • For COM add-ins:
    • Registered only for the current user (HKEY_CURRENT_USER registry hive):

      HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\Addins\<MyAddin>, CommandPreload value.

      where <version> can be:
      • 7.0 for Visual Studio .NET 2002
      • 7.1 for Visual Studio .NET 2003
      • 8.0 for Visual Studio 2005
      • 9.0 for Visual Studio 2008
      • 10.0 for Visual Studio 2010
      • 11.0 for Visual Studio 2012

      The value can be:
      • 1: indicates that the ext_cm_UISetup flag will be used for that add-in the next time that Visual Studio .NET is launched.
      • 2: indicates that the flag was already used.
    • Registered for all users (HKEY_LOCAL_MACHINE registry hive):

      HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\PreloadAddinState, <MyAddIn> value

      where <version> can be:
      • 7.0 for Visual Studio .NET 2002
      • 7.1 for Visual Studio .NET 2003
      • 8.0 for Visual Studio 2005
      • 9.0 for Visual Studio 2008
      • 10.0 for Visual Studio 2010
      • 11.0 for Visual Studio 2012

      The value can be:
      • 1: indicates that the ext_cm_UISetup flag will be used for that add-in the next time that Visual Studio .NET is launched.
      • 2: indicates that the flag was already used.

      Notice that for COM add-ins registered for all users while the CommandPreload registry entry is stored in the HKEY_LOCAL_MACHINE registry hive, since the state must be stored per user, the HKEY_LOCAL_MACHINE registry hive can not be used and the HKEY_CURRENT_USER hive is used instead.
  • For XML add-ins (Visual Studio 2005 or higher):

    HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\PreloadAddinStateManaged, <MyAddIn> value
     
    where <version> can be:
    • 8.0 for Visual Studio 2005
    • 9.0 for Visual Studio 2008
    • 10.0 for Visual Studio 2010
    • 11.0 for Visual Studio 2012

    The value can be:
    • 1: indicates that the ext_cm_UISetup flag will be used for that add-in the next time that Visual Studio .NET is launched.
    • 2: indicates that the flag was already used.

So, you can force a new ext_cm_UISetup phase just by changing the above value from 2 to 1. That will not delete the commands of the add-in, though.

If you want to completely reset the add-in, deleting its commands and user interface, you can use the following procedure:

  • Close all IDE instances.
  • Open a Visual Studio .NET Command Prompt ("Run...", "Programs", "Visual Studio .NET", "Visual Studio .NET Tools", "Visual Studio .NET Command Prompt")
  • Type the following command:
    • For Visual Studio .NET 2002/2003:

      devenv.exe /reset

      That will delete all the commands of all the add-ins and their permanent commandbars, buttons, etc., resetting also their PreloadAddinState value. So, the next time that the IDE starts, they will receive the ext_cm_UISetup flag.

      Notice that using the /reset flag causes also some undesirable effects in the IDE since some user customizations are lost too, specially in Visual Studio .NET 2002.

    • For Visual Studio 2005 or higher:

      devenv.exe /resetaddin Namespace.Class

      where Namespace.Class is the fully qualified name of the main class of the add-in (the Connect class).

      This is a less drastic method to reset an add-in than using devenv.exe /reset.

      If you create a Visual Studio 2005 (or higher) add-in and you go to its properties pages, Debug section, you will notice that there is a command line argument of the form /resetaddin MyAddin.Connect. That gives the add-in the chance of regenerating its commands each time you debug it. You can use this approach to remove the commands of the add-in when it is uninstalled: if you delete the registry entries and/or XML file and then you execute the above statement, the commands of the add-in will be deleted, and since the add-in is uninstalled there will not be a new ext_cm_UISetup phase for it. See HOWTO: Removing commands and UI elements during Visual Studio .NET add-in uninstallation

      Note: devenv.exe /resetaddin doesn't remove permanent commandbars created by the add-in, only its commands and the buttons created from its commands.

      To reset all add-ins you can use:

      devenv.exe /resetaddin *

Related articles



Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)


Top