Logo
HOWTO: Getting properties from the DTE.Properties collection of Visual Studio .NET.

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: September 2005   Microsoft Visual Studio .NET 2003
Updated: March 2013   Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010
      Microsoft Visual Studio 2012
Introduction

This article describes how to get properties from the DTE.Properties collection from a Visual Studio .NET add-in or macro.

More Information

Visual Studio .NET provides many options to customize it through the "Tools", "Options" menu. In this Options window you can select a category (folder) and a page (node) on the left part of the window and then the properties for that page are displayed to the right. When you need to set or get a property value programmatically, you have to use the EnvDTE.DTE.Properties method, which returns an indexed EnvDTE.Properties object. The EnvDTE.DTE.Properties method receives two string parameters: the category and the page, whose values may be difficult to guess for a given the property. There are two ways to get the category and the page for a property:

  • To read the Visual Studio .NET documentation about DTE.Properties names:

    Determining the Names of Property Items in Options Pages
    http://msdn.microsoft.com/en-us/library/ms165642.aspx

  • To use regedit.exe tool to search in the Windows registry the categories, pages and property names, which are located at:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\<version>\AutomationProperties

    Where <version> is:
    • 7.0 for Visual Studio .NET 2002
    • 7.1 for Visual Studio .NET 2003
    • 8.0 for Visual Studio 2005
    • 9.0 for Visual Studio 2008
    • 10.0 for Visual Studio 2010
    • 11.0 for Visual Studio 2012

    Under that registry key, there are categories (the first argument of DTE.Properties) such as "Environment", "FontsAndColors", "Projects" or "TextEditor". Inside the registry key for each category there are page names (the second argument of DTE.Properties). For example, the "Environment" category has the pages "Documents", "General", "Help", etc.

    Note: that registry entry stores the property names, not the actual values (which being per-user are stored in the HKEY_CURRENT_USER hive).

Notice that:

  • The user interface provided by the Options window may arrange categories, pages and options in a different way than the information stored in the registry.
  • Some properties are not exposed through EnvDTE.Properties, so you may need to read the registry settings directly, which are located for each user at HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\<category>. For example:
    • C# formatting options (introduced by Visual Studio 2005), which you can read from HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\CSharp\Options. Notice however that these settings are updated only when Visual Studio exits, not when they are changed through the Options window.
    • Text Editor \ XAML settings which are not exposed through EnvDTE.Properties for Visual Studio 2008 (Visual Studio 2010 does expose them) at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\AutomationProperties but whose settings are stored for each user at HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\9.0\Text Editor\XAML (notice that this registry entry uses "Text Editor" rather than "TextEditor".
    • Text Editor \ XOML settings for Visual Studio 2008 or 2010 (which are not exposed through EnvDTE.Properties), whose settings are stored for each user at HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\<version>\Text Editor\XOML.


Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)


Top