Ver versión en español    
 
Home
10 Reasons to use MZ-Tools
MZ-Tools 6.0 for VS.NET
Editions
Features
Online Documentation
MZ-Tools SDK
Download
Purchase
Version History (RSS)  
FAQ & Support
MZ-Tools 3.0 for VB6 & VBA
Features
Online Documentation
Download (freeware)
Donations (Paypal)
Version History (RSS)  
FAQ & Support
User Reviews
Community Place
Contact  
For Add-In Developers
About
   
 
User Testimonials

I'm an avid supporter of MZ-Tools. It's a product I couldn't do without and your level of support is outstanding.

Jan Hyde (Visual Basic MVP)

You will soon wonder how you ever lived without it.

Andy Maggs

More user reviews
 
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
      Microsoft Visual Studio 2005

Introduction

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
      Try
         Debug.WriteLine("Name: " & objProperty.Name)
         If objProperty.Value Is Nothing Then
            Debug.WriteLine("Value: Nothing")
         Else
            Debug.WriteLine("Value: " & objProperty.Value.ToString)
         End If
      Catch objException As Exception
         Debug.WriteLine(objException.ToString)
      End Try
      Debug.WriteLine("--------------------------------------------------")
   Next
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)

For project item properties:

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

For project configuration properties:

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

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 back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this

MZ-Tools 6.0 for Visual Studio .NET

You can code, design, locate code and document your apps much faster using VB.NET, C#, C++ or Visual J#:

Buy MZ-Tools Now Download MZ-Tools Demo

   Top