Listing All Solution Project Properties

Published 12 July 07 10:04 PM | john 

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.

Filed under: , ,

Comments

# The Director of Random Technologies said on July 23, 2007 4:01 PM:

While I haven't been posting much here, I have been posting pretty regularly over on my main development

# Noticias externas said on July 23, 2007 5:02 PM:

While I haven't been posting much here, I have been posting pretty regularly over on my main development

Anonymous comments are disabled