Add-In: How to prevent dead CommandBarButtons when Visual Studio or an add-in crashes? RRS feed

  • Question

  • I create an add-in for Visual Studio 2005/2008.

    My add-in follows what mz-tools decribes as temporary UI approach . User interfaces get created each time the add-in is loaded and removed when it gets unloaded. But this has the effect, when eg Visual Studio crashes, that the add-in is not unloaded correctly and the UI does not get removed. The next time Visual Studio is  started, my add-in creates its UI again and this leads to duplicated buttons.

    But even for this problem exists this mz-tools article , that describes how to remove duplicated/dead buttons. It says the add-in should delete and re-create its commands during unload, because deleting a command removes all the associated UI.

    This works well, except that is also removes all the custom user created UI. For example, one user created a custom toolbar with buttons that are binded to commands of my add-in. Everytime the add-in gets unloaded, those custom buttons get removed as well.


    What is the correct procedure to prevent dead/duplicated UI, but keep user created UI intact?

    Tuesday, February 22, 2011 9:25 AM


  • Hello Peter,

    I am the author of the MZ-Tools articles. There is no good solution for this problem using the "temporary UI approach" and in fact the second article describes just "an approach", which has the drawback of lost user customizations. You can switch to the "permanent UI approach", which is the one used by packages too. If you stick to the "temporary UI approach" (as I do), the approach that I will use in the next version of MZ-Tools  is to discourage the creation of custom toolbars by allowing customization of the toolbar(s) provided by my add-in, that is, I provide an options window where the user can select which buttons are visible/invisible in each toolbar of the add-in. My MZ-Tools add-in has tons of buttons so the toolbar(s) are long, and this way the user can shorten them to the number of buttons that she wants. HTH.

    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Tuesday, February 22, 2011 2:43 PM