Skip to content

Instantly share code, notes, and snippets.

@cwe1ss
Created September 30, 2015 08:13
Show Gist options
  • Save cwe1ss/c1d623a24a8b7841b785 to your computer and use it in GitHub Desktop.
Save cwe1ss/c1d623a24a8b7841b785 to your computer and use it in GitHub Desktop.
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