MZ-Tools Articles Series: HOWTO: Controlling the state of command in a Visual Studio add-in

This is another of those questions that appear from time to time in the forums: how to make a command invisible or disabled, how to make it appear only when some condition is true, etc. The answers are in the QueryStatus / AddNamedCommand methods. Since my MZ-Tools add-in does not use a permanent user interface, I was not very interested in this topic or in the optional parameters of the AddNamedCommand method. Finally I decided to investigate about it and I found that, as usual, commands are tricky (as happens with commandbars and buttons) and that there are a couple of bugs (that I reported here) in the extensibility model regarding this that ruin the experience. Each time I am more and more against the permanent user interface in add-ins, which is a half-designed feature, half-implemented and half-tested. Here you have the details:

HOWTO: Controlling the state of command in a Visual Studio add-in

MZ-Tools Articles Series: HOWTO: Use the IVsMonitorSelection interface from a Visual Studio add-in

Ever wanted to know from an add-in whether a context Guid of the EnvDTE80.ContextGuids class, for example vsContextGuidDebugging, vsContextGuidDesignMode, vsContextGuidSolutionExists, vsContextGuidSolutionHasMultipleProjects, vsContextGuidSolutionHasSingleProject, vsContextGuidNoSolution, etc. is active? This new article of mine shows how:

HOWTO: Use the IVsMonitorSelection interface from a Visual Studio add-in

Updated MZ-Tools Article Series: HOWTO: Adding buttons, commandbars and toolbars to Visual Studio .NET from an add-in

I have updated my most popular (by far) article to include information and sample code about how to create permanent commandbars (via Commands.AddCommandBar) instead of temporary commandbars (via CommandBars.Add):

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

I have done this for completeness sake, because as I stated in the previous version of the article, I am not big fan of permanent UI in Visual Studio add-ins and I recommend temporary UI instead, which my MZ-Tools add-in uses. My recommendation against permanent commandbars is now bigger than ever: it took me several hours to get the sample code to work, because if temporary commandbars are difficult to program (as usual), permanent commandbars are even worse, much worse (I didn’t even try to test how to remove them when the add-in is uninstalled, that’s left as exercise for you if interested). You get duplicated commandbars each time you debug the add-in in VS 2005 (as someone else reported in a comment here) thanks to the half baked new /resetaddin command-line switch of VS 2005 that add-in projects use when debugging, which resets the commands and buttons but not the commandbars. Fortunately I managed to solve this, the article shows how.

Using Virtual PC to test Visual Studio “Orcas”

As you may know, Microsoft provides now the CTPs and Betas of Visual Studio “Orcas” (currently Beta 1 at the time of this writing) in the form of virtual machines for Virtual PC, which is great to avoid a second computer or second partition to test it. If you are not very familiar with Virtual PC, as it is my case, you may find interesting some issues that you may encounter when using it:

  • If you are using Windows Vista as your host OS, you need Virtual PC 2007.
  • It is recommended that you change the memory of the virtual machine from the default 384 KB (IIRC) to something like 1024 MB or similar. I am using a Sony Vaio SZ3 with 2 GB of memory so it should run nice.
  • To allow mouse integration and shared folders between the host and guest operating systems, you need the Virtual Machine Additions, which I think that are installed by default with the supplied virtual machine. One thing that confused me a lot is that you can’t set shared folders until the virtual machine is running (the settings appear disabled otherwise). I thought that Virtual Machine Additions were not installed. It would be nice if Microsoft added a warning in the settings to inform that the virtual machine must be running. Otherwise you may think that the Virtual Machine Additions are not installed, which is the warning that appears in the explanation of the setting.
  • I have found that the contents of the subfolders of a shared folder were incorrect the day after setting the shared folder: when opening a subfolder, its contents were those of the previous subfolder. Quite strange, it seems a bug. I solved it reassigning the shared folder again.
  • The performance of the shared folder is quite bad, I am not sure how to improve it.
  • You may notice that the mouse cursor disappear as soon as the mouse enters a textbox, or, most importantly, the editor of a code window of VS. Although most mouses have a setting “Hide cursor while typing”, this setting is not the problem. After some investigation, it happens that the problem is the hardware acceleration of the video. You have to right-click on the desktop, select the “Properties” context menu, “Settings” tab, “Advanced” button, “Troubleshoot” button, and change the “Hardware Acceleration” slider from Full to one step less.I hope that some day this Troubleshoot dialog is no longer needed, it is the second time that I have to use it for display problems, and things should work fine without these tweaks.
  • In the March 2007 CTP the virtual machine did not use an undo disk. In the Beta 1 virtual machine, it does, which causes that the dialog that is shown when closing the virtual machine is even more confusing, since it shows a checkbox to commit the changes. Once you understand the dialog without undo disks (Save state, Shutdown, Turn off) and you understand the undo disk feature, all makes sense, but for beginners it is somewhat confusing.

I hope this helps to get you started when evaluating Visual Studio “Orcas” without being distracted by the Virtual PC stuff…

MZ-Tools Articles Series: HOWTO: Create a checked/unchecked command in a Visual Studio add-in

Another question appears from time to time in the forums is how to create a command whose buttons can appear in a checked / unchecked state. Although they are very easy to create, the answer is far from obvious if you don’t know where to look:

HOWTO: Create a checked/unchecked command in a Visual Studio add-in