HOWTO: Guess the names of a Properties collection from a Visual Studio add-in or macro

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


Several classes of the extensibility model have a Properties collection such as:

  • EnvDTE.Solution.Properties
  • EnvDTE.Project.Properties
  • EnvDTE.ProjectItem.Properties
  • EnvDTE.Configuration.Properties

Those collections provide properties that are not part of the class because they can vary from project type or language, etc. Sometimes you are looking for a property but you don't know the name. This article explains how to guess it.

More Information

The obvious way to guess the names in the properties collection is to iterate them with a procedure or macro like this:

Public Sub EnumeratePropeties(ByVal properties As EnvDTE.Properties)
   Dim objProperty As EnvDTE.Property
   For Each objProperty In properties
         Debug.WriteLine("Name: " & objProperty.Name)
         If objProperty.Value Is Nothing Then
            Debug.WriteLine("Value: Nothing")
            Debug.WriteLine("Value: " & objProperty.Value.ToString)
         End If
      Catch objException As Exception
      End Try
End Sub

However, if you are looking for a specific property, several assemblies of the extensibility model (see INFO: Assemblies used in Visual Studio Extensibility) define interfaces whose property members are the names of the properties inside the collection.

For project properties:

  • VSLangProj.ProjectProperties
  • VSLangProj2.ProjectProperties2
  • VSLangProj80.ProjectProperties3
  • VSLangProj80.VBProjectProperties3
  • VsWebSite.WebSiteProperties (hidden)
  • Etc.

For project item properties:

  • VSLangProj.FileProperties (hidden)
  • VSLangProj.FolderProperties (hidden)
  • VSLangProj80.FileProperties2
  • VSLangProj80.FolderProperties2
  • VsWebSite.WebFileProperties (hidden)
  • VsWebSite.WebFolderProperties (hidden)
  • Etc.

For project configuration properties:

  • VSLangProj.ProjectConfigurationProperties
  • VSLangProj2.ProjectConfigurationProperties2
  • VSLangProj80.ProjectConfigurationProperties3
  • VSLangProj80.CSharpProjectConfigurationProperties3
  • VSLangProj80.JSharpProjectConfigurationProperties3
  • Etc.

Notice that you must still use the Properties.Item("property_name") method to get a property. The interfaces are used internally by Visual Studio but from your point of view they are only used to let you know the property names that you can expect in the Properties collection.

Related articles


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