Category Archives: MZ-Tools Articles Series

MZ-Tools Articles Series: BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals

While adding support for SQL Server database projects of VS Team Edition for Database Professionals in my MZ-Tools add-in, I found a nasty bug in the implementation of the ProjectItem.Collection property when the item is a folder:

BUG: ProjectItem.Collection returns a wrong collection for folders of SQL Projects of Visual Studio Team Edition for Database Professionals
http://www.mztools.com/articles/2007/MZ2007031.aspx

I reported it to Microsoft through Microsoft Connect but they closed it without even acknowledging the bug:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=295434

I used Reflector for .NET to examine the internals of the package and I discovered the code that is wrong, so I opened a new one with a more detailed explanation:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=296758

Fortunately once you know the internals of the class that is wrong you can use Reflection to make the correct calls and get the expected result, so the next build of MZ-Tools will support database projects, but I hate when I spend time reporting a bug that will not be fixed or even acknowledged. BTW, they introduced a new bug in VS 2008 that did not exist in VS 2005:

EditPoint.FindPattern causes InvalidCastException on SQL editor of VSTS for DB Professional projects
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=295427

I wish they fix that one…

MZ-Tools Articles Series: HOWTO: Use the system font in dialogs and toolwindows of a Visual Studio add-in

While Visual Studio .NET 2002/2003 use their own font setting for dialogs and toolwindows, Visual Studio 2005 and higher honor the system font, which in Windows Vista is no longer the Tahoma 8.25pt of Windows XP or Windows 2000. See how to do it in your own add-in with my latest article: 

HOWTO: Use the system font in dialogs and toolwindows of a Visual Studio add-in
http://www.mztools.com/articles/2007/MZ2007030.aspx

MZ-Tools Articles Series: HOWTO: Performing some action before or after a build from a Visual Studio macro or add-in

Another question that appear frequently in the forums is how to perform some action before or after a build, how to build programmatically or how to retrieve build configurations. My latest article is about that: 

HOWTO: Performing some action before or after a build from a Visual Studio macro or add-in
http://www.mztools.com/articles/2007/MZ029.htm

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.

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