ProjectsMissingInSolution.ps1
$ErrorActionPreference = "Stop" | |
# Parameters | |
$baseFolder = (Get-Item (Get-Location)).Parent.FullName + "\" | |
$slnName = "All.sln" | |
$excludePatterns = @("Some\Exclusion") | |
# ################################################################ | |
$slnFile = Join-Path $baseFolder $slnName | |
$slnContent = [System.IO.File]::ReadAllText($slnFile) | |
$projectFiles = [System.IO.Directory]::GetFiles($baseFolder, "*.csproj", [System.IO.SearchOption]::AllDirectories) | |
$projectFiles += [System.IO.Directory]::GetFiles($baseFolder, "*.xproj", [System.IO.SearchOption]::AllDirectories) | |
# Exclude projects from configured patterns | |
[regex] $excludeMatchRegEx = ‘(?i)‘ + (($excludePatterns | foreach {[regex]::escape($_)}) –join “|”) + ‘’ | |
$projectFiles = $projectFiles | | |
where { $excludePatterns -eq $null -or $_.Replace($baseFolder, "") -notmatch $excludeMatchRegEx} | |
# Find missing projects | |
$missingProjects = $projectFiles | | |
Where { $slnContent.IndexOf($_.Replace($baseFolder, ""), [System.StringComparison]::OrdinalIgnoreCase) -lt 0; } | |
# Output results | |
$missingProjects | |
"" | |
"Projects missing in solution: " + $missingProjects.Count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment