Getting .Net Framework version of a DLL using Powershell

工作需求要辨識別部門送來的 dll 使用的 .Net FrameWork 是哪一種版本。參考了這篇 Getting .Net Framework version of a DLL using Powershell 裡面提的 :

$dllfile = 'SevenZipSharp.dll'
$sb = {$_.AttributeType.Name -eq 'TargetFrameworkAttribute'}
[Reflection.Assembly]::ReflectionOnlyLoadFrom($dllfile).CustomAttributes.Where($sb).ConstructorArguments.Value

另外蠻多文章都跟這篇 Get .NET Framework Version of a DLL 的解法一樣 :

[Reflection.Assembly]::ReflectionOnlyLoadFrom("C:\SomeTest.dll").ImageRuntimeVersion 

但這個回傳的是 CLR 的版本1。😵