Skip to content

Instantly share code, notes, and snippets.

@Manuel-S
Last active August 29, 2015 14:09
Show Gist options
  • Save Manuel-S/292a176efdaf6e058170 to your computer and use it in GitHub Desktop.
Save Manuel-S/292a176efdaf6e058170 to your computer and use it in GitHub Desktop.
Parses a Solution file to check all projects for missing content files. Useful as a pre-deployment-packaging step.
#requires -version 2.0
[CmdletBinding()]
param (
[parameter(Mandatory=$true)]
[ValidateScript({ Test-Path -Path $_ -PathType Leaf })]
[string]
$Path
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$Path = ($Path | Resolve-Path).ProviderPath
$SolutionRoot = $Path | Split-Path
$SolutionProjectPattern = @"
(?x)
^ Project \( " \{ ( FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
|603C0E0B-DB56-11DC-BE95-000D561079B0
|F85E285D-A4E0-4152-9332-AB1D724D3325
|E53F8FEA-EAE0-44A6-8774-FFD645390401
|E3E379DF-F4C6-4180-9B81-6769533ABE47
|8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942
|F2A71F9B-5D33-465A-A702-920D77279786
|EFBA0AD7-5A72-4C68-AF49-83D382785DCF
|593B0543-81F6-4436-BA1E-4747859CAAE2
|EC05E597-79D4-47f3-ADA0-324C4F7C7484
|3AC096D0-A1C2-E12C-1390-A8335801FDAB
|F184B08F-C81C-45F6-A57F-5ABD9991F28F
|349C5851-65DF-11DA-9384-00065B846F21
|E24C65DC-7377-472B-9ABA-BC803B73C61A
|3D9AD99F-2412-4246-B90B-4EAA41C64699
|76F1466A-8B6D-4E39-A767-685A06062A39
|C089C8C0-30E0-4E22-80C0-CE093F111A43
|DB03555F-0C8B-43BE-9FF9-57896B3C5E56
|60DC8134-EBA5-43B8-BCC9-BB4BC16C2548
|BC8A1FFA-BEE3-4634-8014-F334798102B3
|EFBA0AD7-5A72-4C68-AF49-83D382785DCF
|6BC8ED88-2882-458C-8E55-DFD12B67127B
|6D335F3A-9D43-41b4-9D22-F6F17C4BE596) \} " \)
\s* = \s*
" (?<name> [^"]* ) " , \s+
" (?<path> [^"]* ) " , \s+
"@
Get-Content -Path $Path |
ForEach-Object {
if ($_ -match $SolutionProjectPattern) {
$ProjectPath = $SolutionRoot | Join-Path -ChildPath $Matches['path']
$ProjectPath = ($ProjectPath | Resolve-Path).ProviderPath
$ProjectRoot = $ProjectPath | Split-Path
$ProjectName = [io.fileinfo] $ProjectPath | % basename
[xml]$Project = Get-Content -Path $ProjectPath
$nm = New-Object -TypeName System.Xml.XmlNamespaceManager -ArgumentList $Project.NameTable
$nm.AddNamespace('x', 'http://schemas.microsoft.com/developer/msbuild/2003')
$nodes = $Project.SelectNodes('/x:Project/x:ItemGroup/x:Content', $nm)
# TypeScriptCompile is not a part of the namespace so we need to remove it before being able to access these entries
$xml = New-Object xml
[xml]$xml = ([String](Get-Content -Path $ProjectPath ) -replace 'xmlns.*?">','>' )
$nodes += $xml.SelectNodes('/Project/ItemGroup/TypeScriptCompile')
$nodes | ForEach-Object {
if ($_.Include) {
$RefPath = $ProjectRoot | Join-Path -ChildPath $_.Include
if(!(test-path -path $RefPath)) {
Write-Host "Project: $ProjectName, File: "$RefPath
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment