Last active
November 24, 2018 23:35
-
-
Save chrisoldwood/f053bbb5a08f112b72f4fc189fccee63 to your computer and use it in GitHub Desktop.
List Visual Studio solution file project build configurations.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.synopsis | |
Shows which build configurations are supported for which projects in a | |
Visual Studio solution file (.sln). | |
.description | |
With a large Visual Studio solution that has more than just the default | |
build configurations it's easy for them to get out of step. This script | |
analyses a .sln file and shows you which build configurations are | |
available for which projects so that you can find inconsistencies. | |
.parameter SolutionFile | |
The Visual Studio solution file (.sln) to analyse. | |
#> | |
Param( | |
[Parameter(Position=0,Mandatory=1)] | |
[string] $SolutionFile | |
) | |
Set-StrictMode -Version Latest | |
$ErrorActionPreference = 'stop' | |
if (!(Test-Path $SolutionFile)) | |
{ | |
throw ("Invalid path: {0}" -f $SolutionFile) | |
} | |
$itemFolder = '{2150E333-8FDC-42A3-9474-1A3956D46DE8}' | |
$projectRegex = 'Project\("(?<Type>[^"]+)"\) = "(?<Name>[^"]+)", "(?<File>[^"]+)", "(?<Guid>[^"]+)"' | |
$configRegex = '\s+(?<guid>{[^}]+})\.(?<config>.+)\.Build\.0 = (?<config2>.+)' | |
$projectNames = @{} | |
$buildConfigurations = @{} | |
foreach ($line in Get-Content $SolutionFile) | |
{ | |
if ( ($line -match $projectRegex) -and ($matches.Type -ne $itemFolder) ) | |
{ | |
if (!$projectNames.ContainsKey($matches.Guid)) | |
{ | |
$projectNames[$matches.Guid] = $matches.Name | |
} | |
} | |
if ($line -match $configRegex) | |
{ | |
if (!$buildConfigurations.ContainsKey($matches.Guid)) | |
{ | |
$buildConfigurations[$matches.Guid] = @() | |
} | |
$buildConfigurations[$matches.Guid] += $matches.Config | |
} | |
} | |
foreach ($project in ($projectNames.GetEnumerator() | Sort Value)) | |
{ | |
$configs = ($buildConfigurations[$project.Key] | Sort) -join ', ' | |
Write-Output ('{0}: {1}' -f $project.Value, $configs) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This script shows which build configurations are supported for which projects in a Visual Studio solution file (.sln). It's intended to help highlight where build configurations might be out of line when you have multiple custom configurations.
Here is a very simple example of the output: