Skip to content

Instantly share code, notes, and snippets.

@chrisoldwood
Last active November 24, 2018 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisoldwood/f053bbb5a08f112b72f4fc189fccee63 to your computer and use it in GitHub Desktop.
Save chrisoldwood/f053bbb5a08f112b72f4fc189fccee63 to your computer and use it in GitHub Desktop.
List Visual Studio solution file project build configurations.
<#
.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)
}
@chrisoldwood
Copy link
Author

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:

> PowerShell -File ShowProjectBuildTypes.ps1 FarmMonitor.sln
Core: Debug|Win32, Release|Win32
FarmMonitor: Debug|Win32, Release|Win32
NCL: Debug|Win32, Release|Win32
Test: Debug|Win32, Release|Win32
Wcl: Debug|Win32, Release|Win32
WMI: Debug|Win32, Release|Win32
XML: Debug|Win32, Release|Win32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment