Listing All Solution Project Properties
Don't ask why, but I needed to list all the properties of all the projects in a solution. Here's the macro that did it for me:
Sub ListProjectProperties()
Dim pane As EnvDTE.OutputWindowPane
pane = Utilities.GetOutputWindowPane("Output")
Dim projects As EnvDTE.Projects
projects = DTE.Solution.Projects
If (projects.Count > 0) Then
For Each project As EnvDTE.Project In projects
pane.OutputString(project.Name + ": " + vbCrLf)
Dim props As EnvDTE.Properties
props = project.Properties
If Not props Is Nothing Then
For Each prop As EnvDTE.Property In props
Dim propType As String
propType = "Unknown"
Try
If prop.Value Is Nothing Then
propType = "Nothing"
Else
propType = prop.Value.GetType().ToString()
End If
Catch e As System.Reflection.TargetParameterCountException
' Just don't explode
End Try
pane.OutputString(" " + prop.Name + " (" + propType + ")" + vbCrLf)
Next
End If
Next
Else
pane.OutputString("No projects in solution" + vbCrLf)
End If
End Sub
The crazy part is TargetParameterCountException that occasionally gets thrown when calling ToString() on the Value property Type. Perhaps some .NET/COM expert can shed light on that little mystery for me.