How do I programmatically list all projects in a solution?

Kiquenet picture Kiquenet · Sep 27, 2010 · Viewed 31.6k times · Source

How do I programmatically list all of the projects in a solution? I'll take a script, command-line, or API calls.

Answer

brianpeiris picture brianpeiris · Sep 27, 2010

Here's a PowerShell script that retrieves project details from a .sln file:

Get-Content 'Foo.sln' |
  Select-String 'Project\(' |
    ForEach-Object {
      $projectParts = $_ -Split '[,=]' | ForEach-Object { $_.Trim('[ "{}]') };
      New-Object PSObject -Property @{
        Name = $projectParts[1];
        File = $projectParts[2];
        Guid = $projectParts[3]
      }
    }