Skip to content

Instantly share code, notes, and snippets.

@jstangroome
Created August 30, 2010 09:34
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save jstangroome/557222 to your computer and use it in GitHub Desktop.
Save jstangroome/557222 to your computer and use it in GitHub Desktop.
Get-VSSolutionReferences.ps1
#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
}
}
}
@lontivero
Copy link

Some times, HintPath and SpecificVersion are not present.

@big-shadow
Copy link

Nice!
I'm going to fork this, and give it whirl. In my case, I want to remove references to missing files.

@rokaw
Copy link

rokaw commented Sep 14, 2017

changes in .proj (ex. hintPath) is not getting reflected in VS solution explorer.
How to fix this?

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