Forked from jstangroome/Get-VSSolutionReferences.ps1
Created
February 16, 2016 20:16
-
-
Save big-shadow/70f2f61740d35ad4351a to your computer and use it in GitHub Desktop.
Get-VSSolutionReferences.ps1
This file contains hidden or 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
#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 \} " \) | |
\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 | |
[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') | |
$Project.SelectNodes('/x:Project/x:ItemGroup/x:Reference', $nm) | | |
ForEach-Object { | |
$RefPath = $null | |
if ($_.HintPath) { | |
$RefPath = $ProjectRoot | Join-Path -ChildPath $_.HintPath | |
} | |
New-Object -TypeName PSObject -Property @{ | |
ProjectPath = $ProjectPath | |
AssemblyName = New-Object -TypeName Reflection.AssemblyName -ArgumentList $_.Include | |
Path = $RefPath | |
SpecificVersion = [Convert]::ToBoolean($_.SpecificVersion) | |
} | | |
Add-Member -Name Name -MemberType ScriptProperty -Value { | |
$this.AssemblyName.Name | |
} -PassThru | | |
Add-Member -Name Exists -MemberType ScriptMethod -Value { | |
try { | |
return Test-Path -Path $this.Path -PathType Leaf | |
} catch { | |
return $false | |
} | |
} -PassThru | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment