Category Archives: MZ-Tools Articles Series

Getting properties from the DTE.Properties collection

I have updated an article that I wrote back in 2005:

HOWTO: Getting properties from the DTE.Properties collection of Visual Studio .NET.
http://www.mztools.com/articles/2005/MZ2005008.aspx

And the reason is that I have found lately that guessing the names of properties to index DTE.Properties(category, page) is not as easy as reading the MSDN documentation (whose list may not be up-to-date) or using regedit.exe to inspect the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<version>\AutomationProperties registry entry. Specifically I have found that:

– There is no way through automation (EnvDTE) to get the C# formatting options that were introduced by VS 2005.

– Text Editor XAML settings are not exposed through DTE.Properties in VS 2008 but they are in VS 2010 (something that the MSDN docs don’t reflect yet and I doubt they will)

– Text Editor XOML settings are not exposed through DTE.Properties even in VS 2010.

I guess that some SDK service can get that information, or maybe it is something not exposed by the owner package of those settings. So I am using the other way, which is to read directly the actual property values from the HKEY_CURRENT_USER hive. But it is also tricky, because the term “TextEditor” can become “Text Editor”, “PlainText” can become “Plain Text” and the C# formatting settings seem to be updated only when VS closes and not when the Options dialog is closed (and they seem to appear only if they differ from the defaults)…

MZ-Tools Articles Series: BUG: EnvDTE.CodeFunction.Parameters causes COM Exception with C# event add/remove methods in Visual Studio macros or add-ins

And yet another bug in the file code model of C# that happens with events:

BUG: EnvDTE.CodeFunction.Parameters causes COM exception with C# event add/remove methods in Visual Studio macros or add-ins:
http://www.mztools.com/articles/2009/MZ2009019.aspx

Curiously this didn’t happen with VS.NET 2002/2003 when CodeEvent didn’t exist (it was introduced as EnvDTE80.CodeEvent in VS 2005) and C# events were mapped to EnvDTE.CodeProperty.

I have also reported it to Microsoft through Microsoft Connect.

MZ-Tools Articles Series: BUG: EnvDTE.CodeFunction.Attributes doesn’t work with C# property get/set methods in Visual Studio macros or add-ins

Another bug of the file code model for C#:

BUG: EnvDTE.CodeFunction.Attributes doesn’t work with C# property get/set methods in Visual Studio macros or add-ins
http://www.mztools.com/articles/2009/MZ2009018.aspx

It happens too in VS 2010 Beta 1, I have reported it to Microsoft. Hopefully it can get fixed.

MZ-Tools Articles Series: BUG: C# indexers are not mapped to EnvDTE80.CodeProperty2 in Visual Studio macros or add-ins

Another bug that I have found today:

BUG: C# indexers are not mapped to EnvDTE80.CodeProperty2 in Visual Studio macros or add-ins
http://www.mztools.com/articles/2009/MZ2009017.aspx

It only happens in VS 2005 and VS 2008. Curiously it is already fixed in VS 2010 Beta 1.

If you need to access the parameter collection of a C# indexer, since EnvDTE.CodeProperty lacks a Parameters property and you can’t get an EnvDTE80.CodeProperty2 (which doesn’t lack it), you need to use the Getter or Setter properties of EnvDTE.CodeProperty and use the EnvDTE.CodeFunction.Parameters property.

MZ-Tools Articles Series: BUG: EnvDTE.CodeElement.GetStartPoint(vsCMPart.vsCMPartBody) returns wrong result for VB.NET classes using the Implements or Inherits clauses

This is a bug that I have found twice in the last couple of days:

EnvDTE.CodeElement.GetStartPoint(vsCMPart.vsCMPartBody) returns wrong result for VB.NET classes using the Implements or Inherits clauses
http://www.mztools.com/articles/2009/MZ2009016.aspx

The bug was not present in VS.NET 2003, it appeared in VS 2005, it is in VS 2008 and also in VS 2010 Beta 1. You can vote to get it fixed here:

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

MZ-Tools Articles Series: BUG: EnvDTE.Project.CodeModel doesn’t retrieve attributes in the AssemblyInfo file

If you are trying to retrieve attributes in the assemblyinfo file, it’s better to use the ProjectItem.FileCodeModel rather than the Project.CodeModel:

BUG: EnvDTE.Project.CodeModel doesn’t retrieve attributes in the AssemblyInfo file
http://www.mztools.com/articles/2009/MZ2009014.aspx

The bug report for Microsoft is here:

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

MZ-Tools Articles Series: PRB: PEVerify.exe causes problem verifying add-in with referenced assemblies from Visual Studio not in the GAC

I am currently working on a new version of MZ-Tools and yesterday I updated its build script. When running it, to my surprise, I found the following error in the step that verifies the assembly with the peverify.exe tool after the obfuscation step:

Error 0x80070002 “The system cannot find the file specified”

After diagnosing the problem with the Assembly Binding Log Viewer, I found that the file in question was the Microsoft.VisualStudio.Data.Interop.dll assembly that this version of MZ-Tools will reference for one of its features. This file, on the contrary to others such as Microsoft.VisualStudio.Shell.Interop.8.0.dll, does not reside on the Global Assembly Cache (GAC) and, as any Visual Studio assembly, should not be distributed, the VS IDE will find it. However, when using the peverify.exe tool, that referenced assembly is not found.

Fortunately Microsoft has ways to fix for all these problems through a .config file. Long time ago I posted how to fix the problem PEVerify.exe causes problem with EnvDTE.dll verifying Visual Studio 2005 add-ins and this new article explains how to fix this other problem:

PRB: PEVerify.exe causes problem verifying add-in with referenced assemblies from Visual Studio not in the GAC
http://www.mztools.com/articles/2009/MZ2009013.aspx

MZ-Tools Articles Series: updated articles

I have updated the following MZ-Tools Series articles to fix/explain better some things, provide C# code some cases, cover Windows Vista folders, cover Visual Studio 2008/2010 in some other cases, etc:

HOWTO: Removing commands and UI elements during Visual Studio .NET add-in uninstallation
http://www.mztools.com/Articles/2005/MZ2005002.aspx

HOWTO: Reset a Visual Studio add-in
http://www.mztools.com/Articles/2006/MZ2006014.aspx

HOWTO: Get rid of a Visual Studio add-in
http://www.mztools.com/Articles/2006/MZ2006018.aspx

INFO: Visual Studio .NET Add-In Commands Disappear On Next Session
http://www.mztools.com/Articles/2005/MZ2005014.aspx

MZ-Tools Articles Series: BUG: Infinite recursion in add-in causes Visual Studio crash

This bug that I commented in a previous blog entry and that I reported to Micorosoft through Microsoft Connect is not going to be fixed in the next version VS 2010:

Add-in causing stack overflow causes “Microsoft Visual Studio has encountered a problem and needs to close”
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=414301

So, there will be three versions of Visual Studio affected. I have written a MZ-Tools article to document it:

BUG: Infinite recursion in add-in causes Visual Studio crash
http://www.mztools.com/articles/2009/MZ2009004.aspx