Skip to content

Instantly share code, notes, and snippets.

@mkropat
Last active October 6, 2017 14:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkropat/fa8b03dbcff8b9184b20 to your computer and use it in GitHub Desktop.
Save mkropat/fa8b03dbcff8b9184b20 to your computer and use it in GitHub Desktop.
[CmdletBinding()]
param(
[string]$AssemblyName,
[string]$Path
)
function Get-AssemblyReverseReferences {
param(
[string]$Name,
[string]$Path = '.'
)
Get-Assemblies $Path |
ForEach-Object {
$reference = $_.References | Where-Object { $_.Name -eq $Name } | Select-Object -First 1
if ($reference) {
[PSCustomObject]@{
AssemblyFile = $_.AssemblyFile
Reference = $reference
}
}
}
}
function Get-Assemblies {
param($Path)
Get-ChildItem -Path $Path -Recurse -Filter '*.dll' | ForEach-Object {
try {
$asm = Get-Assembly $_.FullName
@{
AssemblyFile = $_
References = $asm.GetReferencedAssemblies() | Sort-Object -Property Name
}
}
catch [BadImageFormatException] {
}
catch [IO.FileLoadException] {
}
catch [Security.SecurityException] {
}
}
}
function Get-Assembly {
[OutputType([System.Reflection.Assembly])]
param($Path)
$fileName = Resolve-Path $Path
[System.Reflection.Assembly]::LoadFile($fileName)
}
Get-AssemblyReverseReferences -Name $AssemblyName -Path $Path |
ForEach-Object { [PSCustomObject]@{
Dll = (Resolve-Path -Relative $_.AssemblyFile.FullName)
Reference = $_.Reference
}} |
Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment