How do I programmatically list all projects in a solution?

前端 未结 12 1394
感动是毒
感动是毒 2020-11-29 04:06

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

12条回答
  •  有刺的猬
    2020-11-29 04:42

    Since Visual Studio 2013 the Microsoft.Build.dll provides a SolutionFile object with some very handy functions.

    Here's an example of using the v14.0 version to list the relative path of all the projects in the order they appear in the solution.

    Add-Type -Path (${env:ProgramFiles(x86)} + '\Reference Assemblies\Microsoft\MSBuild\v14.0\Microsoft.Build.dll')
    $solutionFile = ''
    $solution = [Microsoft.Build.Construction.SolutionFile] $solutionFile
    ($solution.ProjectsInOrder | Where-Object {$_.ProjectType -eq 'KnownToBeMSBuildFormat'}).RelativePath
    

    There are plenty of other properties on the project object (ProjectName, AbsolutePath, configurations etc) that may be of use. In the above example I used the ProjectType to filter out Solution Folders.

提交回复
热议问题