Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Macro to list Projects instead of solution folders

Using the following code gives me Solution folders instead of real projects.

projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
    If project.UniqueName = projectName Then
        Return project
    End If
Next

Is there way I can loop through actual Project nodes?

I'm trying to read properties from the startup project.

like image 208
Mrchief Avatar asked Nov 27 '25 09:11

Mrchief


1 Answers

I've never written any Visual Studio macros, but this may be what you are looking for.

projectName = DTE.Solution.SolutionBuild.StartupProjects(0)
For Each project In DTE.Solution.Projects
    If (project.ConfigurationManager IsNot Nothing) Then
        ' It's a project!
        If (project.UniqueName = projectName) Then Return project
    Else
        If (project.ProjectItems IsNot Nothing) Then
            For Each projectItem In project.ProjectItems
                If (projectItem.SubProject IsNot Nothing) Then
                   ' TODO: Recurse on projectItem.SubProject 
                End If
            Next
        End If
    End If
Next

I left a 'TODO in there, because you would need to actually pull this out into a function that you could recursively call if you are looking to deal with nested (sub) projects.

I got this solution from this link, and while it's Visual Studio 2005-era material, it might get you going in the right direction.

like image 178
ckittel Avatar answered Nov 30 '25 00:11

ckittel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!