Accessing project properties from a VS macro

I saw this question on a newsgroup: How do you access the properties of a project via the EnvDTE VS extensibility interface? It’s really quite simple, like in this code:

Sub AccessProject()
  Dim proj As Project
  proj = DTE.Solution.Projects.Item(1)
  Dim prop As [Property]
  For Each prop In proj.Properties
    Debug.Print("Project property " & prop.Name & " = " & prop.Value)
  Dim projItem As ProjectItem
  For Each projItem In proj.ProjectItems
    Debug.Print("Project item " & projItem.Name)
End Sub

This will simply print out all the project properties and items it finds. The sample accesses only the first entry in the solution’s Projects list – you can directly access other specific members in a similar way, of course, and it’s also possible to find the currently active project(s) via the DTE.ActiveSolutionProjects:

Dim projects as System.Array = DTE.ActiveSolutionProjects
Dim proj as Project

For Each proj In projects

Leave a Comment

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s