-
-
Save jstangroome/499779 to your computer and use it in GitHub Desktop.
Get-AssemblyReferences
This file contains 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 -PathType Leaf })] | |
[string] | |
$Path | |
) | |
$ErrorActionPreference = 'Stop' | |
Set-StrictMode -Version Latest | |
Write-Output $Path | |
$ParentPath = $Path | Split-Path -Parent -Resolve | |
$TempDomainName = 'TempDomain' + [Guid]::NewGuid().ToString() | |
$DomainSetup = New-Object -TypeName AppDomainSetup | |
$DomainSetup.ApplicationBase = $ParentPath | |
$TempDomain = [AppDomain]::CreateDomain($TempDomainName, $null, $DomainSetup) | |
$AsmName = [Reflection.AssemblyName]::GetAssemblyName($Path) | |
#[byte[]]$AsmBytes = [IO.File]::ReadAllBytes($Path) | |
write-verbose "Base: $($TempDomain.BaseDirectory)" | |
write-verbose "Rel: $($TempDomain.RelativeSearchPath)" | |
exit | |
$Asm = $TempDomain.Load($AsmName) | |
Write-Verbose "Parsing references" | |
$Asm.GetReferencedAssemblies() | | |
ForEach-Object { | |
$Asm = $TempDomain.Load($_) | |
if (-not $Asm.GlobalAssemblyCache) { | |
Write-Output $_.Location | |
# TODO recurse | |
} | |
} | |
[AppDomain]::Unload($TempDomain) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment