MZ-Tools Articles Series: HOWTO: Get an EnvDTE.Project object from its project unique name

Ever wanted to retrieve an EnvDTE.Project from a given project unique name? Today I have discovered that you don’t have to iterate the projects of a solution to find it:

HOWTO: Get an EnvDTE.Project object from its project unique name
http://www.mztools.com/articles/2007/MZ026.htm

It happened that I was thinking about a Solution.GetProject method, but Microsoft gave it another name 🙂

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
http://www.mztools.com/articles/2007/MZ025.htm

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
http://www.mztools.com/articles/2007/MZ024.htm

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
http://www.mztools.com/articles/2005/MZ003.htm

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
http://www.mztools.com/articles/2007/MZ023.htm

MZ-Tools Articles Series: BUG: EnvDTE.SelectionEvents.OnChange event does not fire when more than two nodes are already selected in the Solution Explorer of Visual Studio

Another bug in the Solution Explorer window that was reported in the forums some time ago:

BUG: EnvDTE.SelectionEvents.OnChange event does not fire when more than two nodes are already selected in the Solution Explorer of Visual Studio
http://www.mztools.com/articles/2007/MZ022.htm

I reported it to the Microsoft Connect site so you can follow the resolution:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=269532

MZ-Tools Articles Series: BUG: EnvDTE.UIHierarchyItems does not work correctly in Visual Studio 2005 if Solution Explorer nodes are not opened previously

Here you have a bug that can happen navigating programatically the nodes of the Solution Explorer of VS 2005 if you have solution folders and their nodes are not expanded by hand previously:

BUG: EnvDTE.UIHierarchyItems does not work correctly in Visual Studio 2005 if Solution Explorer nodes are not opened previously
http://www.mztools.com/articles/2007/MZ021.htm

I am not sure if Microsoft will consider a bug or a side-effect of the optimizations made in VS 2005 to open the solutions faster, but, for me, it is a bug and I reported it here:

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=269526

You can vote for it if you consider it a bug too.

Visual Studio “Orcas” add-ins don’t appear in the Add-In Manager (March 2007 CTP)

If you have tried to create an add-in with the wizard in the March 2007 CTP of Visual Studio “Orcas”, you will have noticed that when you try to debug the add-in, it is not loaded. In fact, it does not appear in the Add-In Manager of the second instance of Visual Studio. This is because this CTP still places the .AddIn linked file (the one with the little arrow in the Solution Explorer) in the folder “C:\Documents and Settings\<user>\My Documents\Visual Studio 2005\AddIns”. To solve it:

  • Create the folder “AddIns” inside the folder “C:\Documents and Settings\<user>\My Documents\Visual Studio Codename Orcas” (by default it is not created).
  • Move the .AddIn file to that folder.
  • Remove the linked file from the Solution Explorer and add it pointing to the new location.

VS SDK, packages, add-ins, macros and more…