Category Archives: MZ-Tools Articles Series

MZ-Tools Articles Series: HOWTO: Get the current theme and detect changing it from a Visual Studio 2012 add-in.

I am currently adding support for the Dark / Light themes of Visual Studio 2012 in my MZ-Tools 7.0 add-in for Visual Studio, which is resulting much harder than expected because there are a lot of issues. I will blog about them in a future post when the work is done, but meantime I have written this sample to show how an add-in can know the current theme and how to get notified when the theme is changed:

HOWTO: Get the current theme and detect changing it from a Visual Studio 2012 add-in.
http://www.mztools.com/articles/2012/MZ2012012.aspx

One thing that may surprise you is that if you have opened several VS 2012 instances, changing the theme in one of them changes it in ALL of them. So, it is not enough for an add-in to know when the theme has been changed through the Tools, Options window of the instance where it is hosted. Visual Studio 2012 broadcasts a

WM_SYSCOLORCHANGE message
, so an add-in must intercept that message through some top-level window. While an add-in could do subclassing of the main IDE window, that’s an approach prone to crashes if two extensions do the same (because subclassing must be undone in reverse order), so my sample uses a dummy invisible top-level form.

The new Visual Studio 2012 IDE and SDK introduces new services and methods related to themes, for example the IVsShell5 interface of the Microsoft.VisualStudio.Shell.Interop.11.0.dll assembly, so maybe there is some other way to get notified when the theme changes (I don’t know), but my approach with MZ-Tools is to use a single binary add-in dll, so I can’t add as references assemblies that are not in VS 2005, as I explained in the article:

HOWTO: Create an add-in that targets several Visual Studio versions with the same add-in DLL using C# or VB.NET.
http://www.mztools.com/articles/2011/MZ2011012.aspx

MZ-Tools Articles Series: HOWTO: Generate Interop assemblies to create an add-in for the VBA editor (32-bit or 64-bit) of Office with Visual Studio .NET.

This is the first article of the series devoted to creating add-ins for the VBA editor (32-bit / 64-bit) of Microsoft Office that I announced here.

It discusses the use of private vs Primary Interop Assemblies for Office, the .NET Framework 2.0 vs 4.0 to use and how to generate the private interop assemblies.

HOWTO: Generate Interop assemblies to create an add-in for the VBA editor (32-bit or 64-bit) of Office with Visual Studio .NET.
http://www.mztools.com/articles/2012/MZ2012011.aspx

MZ-Tools Articles Series: Changing gears (just a little bit)

For the past years I have been writing articles in the MZ-Tools Series and posts in this blog about developing add-ins with Visual Studio .NET for Visual Studio .NET, using the .NET Framework. All this knowledge comes from my experience developing since 2002 the versions 4.0, 5.0, 6.0 and 7.0 of my MZ-Tools add-in for Visual Studio. As you may know, I have also the MZ-Tools 3.0 version for Visual Basic 6.0, 5.0 and the VBA editor, that I created with Visual Basic 6.0 back in 2000.

When Office 2010 came out, for the first time there was a 64-bit version, not only a 32-bit version, and, alas, the VBA editor of the 64-bit version doesn’t support 32-bit COM add-ins. So, MZ-Tools 3.0 for VBA doesn’t support Office 2010 64-bit. I have received some requests to support it, and things only will get worse as more developers install the 64-bit version. The same is happening to other developers creating add-ins for the VBA editor. Until now, the common answer was that it was not possible, since VB6 can only create 32-bit COM add-ins and Office 2010 64-bit can’t use 32-bit COM add-ins.

About 3 months ago I devoted some thoughts about it and I got the idea of developing an add-in for the VBA editor of Office 64-bit using the .NET Framework, since .NET assemblies can be 64-bit, and .NET assemblies can be registered as COM components… I was so excited that I halted the development of MZ-Tools 7.0 during a week to make a prototype and after several difficulties…I succeeded  :-).

Not only I got a Hello World prototype, but I also managed to create toolbars, buttons, toolwindows, to use a single NET .dll and setup to target the 32-bit and 64-bit versions of the VBA editor and as bonus tracks, to install the add-in without admin rights and to avoid the use of the clipboard to use custom pictures in buttons (two common sources of issues of MZ-Tools 3.0 for VBA).

So I am going to write a few articles in the next weeks to document the whole approach from start (Hello World) to end (the setup). Of course, I will keep writing about Visual Studio add-ins.

PS: the (great) future of MZ-Tools 3.0 for VB6/VB5/VBA will be announced in the MZ-Tools blog in the next months.

MZ-Tools Articles Series: HOWTO: Get assemblies of the Add Reference dialog from a Visual Studio add-in.

My new tutorial explains how to get the assemblies that Visual Studio shows in the .NET tab of the Add Reference dialog, since they are not the assemblies in the Global Assembly Cache (GAC):

HOWTO: Get assemblies of the Add Reference dialog from a Visual Studio add-in.
http://www.mztools.com/articles/2012/MZ2012010.aspx

So, normally assemblies are located at two places: in some folder (to be used at development time by Visual Studio) and in the GAC (to be used by the application when deployed).

There are rare occasions where an assembly is only in the GAC, but you can even add a reference to an assembly in the GAC as I explained in this other article:

HOWTO: Reference a Visual Studio assembly in the GAC from an add-in
http://www.mztools.com/articles/2007/mz2007012.aspx

MZ-Tools Articles Series: HOWTO: Get loaded add-ins and installed products from a Visual Studio add-in.

I have received several bug reports in the last years about MZ-Tools for Visual Studio .NET that after some investigation I have discovered that the bugs only happen when certain 3rd party add-in or package is installed, or even not installed. For example, this one only happens when CodeRush is installed. And this other one only happens in VS 2008 if the Code Analysis Tools are not installed. And I have found another ones that I have not even documented in this blog, just patching my code to prevent them.

Since diagnosing those bugs is extremely difficult without that information, my new MZ-Tools 7.0 for Visual Studio includes in the bug reports information about loaded add-ins and installed products. I have created an article with a sample add-in to show how to get that information:

HOWTO: Get loaded add-ins and installed products from a Visual Studio add-in.
http://www.mztools.com/articles/2012/MZ2012009.aspx

The article explains too a Registry redirection that Visual Studio 2010 and higher does, which I mentioned the first time in this post.

And you can get even more information to be included in bug reports here:

HOWTO: Detect installed Visual Studio editions, packages or service packs
http://www.mztools.com/articles/2008/MZ2008003.aspx

MZ-Tools Articles Series: BUG: Setting CommandBarPopup.Visible to False doesn’t work when CommandBarPopup in context menu.

When I thought that I have fixed the bug that I explained in my last post, I found another subtle one: in VS 2010 and 2012, setting to False the Visible property of a CommandBarPopup was not honored if the CommandBarPopup was created on a context menu (for example, in the Code Window context menu), but it worked if created on a Toolbar (for example, the Standard toolbar).

This is another bug introduced in the WPF-based commandbars of VS 2010, since it works as expected in VS 2008 and before. Unfortunately I was unable to detect these two bugs back in 2009 during the VS 2010 beta since MZ-Tools 6.0 did not offer the more complete customization offered by the new MZ-Tools 7.0 version to show / hide buttons and dropdown menus. But fortunately, the workaround is as easy as adding the children CommandBarButtons before setting the Visible property to False.

I have written a small article to document it:

BUG: Setting CommandBarPopup.Visible to False doesn’t work when CommandBarPopup in context menu.
http://www.mztools.com/articles/2012/MZ2012008.aspx

And I have reported the bug to Microsoft Connect (currently awaiting to be acknowledged):

https://connect.microsoft.com/VisualStudio/feedback/details/758545/commandbarpopup-visible-false-doesnt-work-when-commandbarpopup-in-context-menu#details

MZ-Tools Articles Series: BUG: CommandbarPopup.Caption changes CommandbarPopup.CommandBar.Name and viceversa.

A couple of days ago a customer of the new version MZ-Tools 7.0 for Visual Studio reported a bug regarding the dropdown menus visibility not preserved across Visual Studio sessions. I isolated the bug which happened to be a bug in the WPF-based commandbars of Visual Studio 2010 (and 2012), not happening in VS 2008 and before.

I have written a small article to document it:

BUG: CommandbarPopup.Caption changes CommandbarPopup.CommandBar.Name and viceversa.
http://www.mztools.com/articles/2012/MZ2012007.aspx

And I have reported the bug to Microsoft Connect (currently awaiting to be acknowledged):

https://connect.microsoft.com/VisualStudio/feedback/details/758550/commandbarpopup-caption-changes-commandbarpopup-commandbar-name-and-viceversa#details

MZ-Tools Articles Series: HOWTO: Create a command with a custom picture using an ImageList for a XML-based Visual Studio add-in.

This one that I mentioned in my last post that I would investigate has been extremely easy:

HOWTO: Create a command with a custom picture using an ImageList for a XML-based Visual Studio add-in.
http://www.mztools.com/articles/2012/MZ2012005.aspx

And Microsoft updated correctly the documentation for Visual Studio 2010 regarding the new possibilities of the Bitmap parameter of the EnvDTE80.Commands2.AddNamedCommand2 method:

EnvDTE80.Commands2.AddNamedCommand2
http://msdn.microsoft.com/en-us/library/envdte80.commands2.addnamedcommand2(VS.100).aspx

MZ-Tools Articles Series: HOWTO: Create a command with a custom picture without using a managed satellite DLL for a XML-based Visual Studio add-in.

I should have written the following article near two years ago, but also Microsoft should have provided this way of creating commands with custom pictures without the need for satellite dlls 10 years ago, since the very beginning of VS.NET 2002:

HOWTO: Create a command with a custom picture without using a managed satellite DLL for a XML-based Visual Studio add-in.
http://www.mztools.com/articles/2012/MZ2012004.aspx

The history has been quite compolicated:

  • Visual Studio .NET 2002 and 2003 only supported COM-based add-ins that required native Visual C++ Win32 satellite dlls to provide custom pictures.
  • Visual Studio 2005 introduced XML-based add-ins (using an .AddIn file to register the add-in within Visual Studio) and managed (VB.NET/C#) satellite dlls.
  • As documented in the Microsoft Connect Bug Report 336868, I requested to Microsoft during the VS 2010 beta to following: “Satellite DLLs (managed or native) should not be required. They may be OK for string localizations, but please don’t force us to create satellite DLLs for pictures that could be in the own assembly add-in.”
  • In the same bug report, Suzanne Hansen (the Program Manager of Visual Studio Platform Shell Team at that time) answered that (in VS 2010) “There will be support for loading a command’s bitmap from the add-in module if there is no satellite DLL or if the satellite DLL doesn’t contain the image.”
  • And that was my knowledge of the matter until two days ago, when while writing the add-ins for the article I discovered that Visual Studio 2008 already supported providing custom pictures in a resource file of the add-in dll rather than through a satellite dll. Alas, the same doesn’t apply to Visual Studio 2005, which insists on finding a “.resources.dll” satellite assembly, which is a pity, because if your add-in targets VS 2005, 2008 and 2010 with the same .NET Framework 2.0 dll, you need to provide the satellite dll.
  • And there is more! As I posted back in 2009, the EnvDTE80.Commands2.AddNamedCommand2 was changed internally in VS 2010 to accept a managed (.NET) System.Drawing.Bitmap or System.Drawing.Icon. I will try it and this will be the subject of another article if I am successful.

MZ-Tools Articles Series: HOWTO: Set the default style a CommandBarButton on a toolbar from a Visual Studio add-in.

When a CommandBarButton is created from a Command on a Visual Studio menu, it has an icon and a text. However, when it is created on a toolbar, it can have only an icon, or an icon and a text. Typically buttons on a toolbar have only an icon (without a text). There are two ways to set that style (only the icon) to a CommandBarButton on a toolbar:

  • Setting the CommandBarButton.Style = MsoButtonStyle.msoButtonIcon. This approach has the drawback that Visual Studio first creates the button with icon and text, and then it changes it to icon only.
  • Setting the default style of a command to EnvDTE80.vsCommandStyle.vsCommandStylePict, so that CommandBarButtons created on toolbars have only the icon, while those created on menus have icon with text (the only possible style for them).

My latest article shows a sample of the second approach:

HOWTO: Set the default style a CommandBarButton on a toolbar from a Visual Studio add-in.
http://www.mztools.com/articles/2012/MZ2012003.aspx