-
Notifications
You must be signed in to change notification settings - Fork 30
/
GetShipFiles.ps1
81 lines (77 loc) · 2.04 KB
/
GetShipFiles.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function Get-DllDependencies([string]$assemblyPath)
{
$dependencies = @();
$assemblyPath = Resolve-Path $assemblyPath;
$folder = Split-Path $assemblyPath;
$assembly = [Reflection.Assembly]::ReflectionOnlyLoadFrom($assemblyPath);
foreach ($a in $assembly.GetReferencedAssemblies())
{
$dependency = Join-Path $folder ($a.Name+".dll");
if (Test-Path $dependency)
{
$dependencies += $dependency;
}
}
return $dependencies;
}
function Get-AllDllDependencies([string]$assemblyPath)
{
$dependencies = Get-DllDependencies($assemblyPath) | sort -unique;
$newDependencies = $dependencies;
(Resolve-Path $assemblyPath).Path
if ($dependencies.GetType() -eq [string])
{
$dependencies
}
else
{
while ($newDependencies.Length -gt 0)
{
$item = $newDependencies[0];
$item
$nd = Get-DllDependencies($item) | sort -unique | where { $dependencies -notcontains $_ };
$dependencies = $dependencies + $nd;
$newDependencies = $newDependencies + $nd;
if ($newDependencies.Length -gt 1)
{
$newDependencies = $newDependencies[1..($newDependencies.Length-1)];
}
else
{
break;
}
}
}
}
function Get-DllShipFiles($dll)
{
if (Test-Path $dll)
{
$dll
}
$xml = [System.IO.Path]::ChangeExtension($dll, "xml");
if (Test-Path $xml)
{
$xml
}
$pdb = [System.IO.Path]::ChangeExtension($dll, "pdb");
if (Test-Path $pdb)
{
$pdb
}
$config = $dll + ".config";
if (Test-Path $config)
{
$config
}
}
function Get-ShipFiles($dlls)
{
$dlls | % { Get-AllDllDependencies($_) } | Sort -Unique | % { Get-DllShipFiles($_) }
}
#Get-ShipFiles(@(
# #"SharpDebug.CodeGen.App.exe",
# "SharpDebug.CommonUserTypes.dll",
# "SharpDebug.DwarfSymbolProvider.dll",
# "SharpDebug.WinDbg.x64.dll",
# "SharpDebug.WinDbg.x86.dll"));