Determine framework (CLR) version of assembly

后端 未结 12 2329
生来不讨喜
生来不讨喜 2020-11-27 03:46

From the command line (or by any means really), how can I determine which CLR version a .NET assembly requires?

I need to determine if an assembly requires 2.0 or 4

12条回答
  •  佛祖请我去吃肉
    2020-11-27 03:56

    Here is a powershell one liner that will display the Target framework version for assemblies targeting v4 and up.

     Resolve-Path($args) | Select @{N='Assembly'; E={$_ }}, @{N='TargetFramework'; E={(([Reflection.Assembly]::ReflectionOnlyLoadFrom($_).GetCustomAttributesData() | Where-Object { $_.AttributeType -like "System.Runtime.Versioning.TargetFrameworkAttribute" })).NamedArguments.TypedValue}} | Format-Table
    

    use:

    C:\test\> show-targetfw.ps1 *.dll
    
    Assembly             TargetFramework
    --------             --------
    C:\test\a.dll        ".NET Framework 4.6.1"
    C:\test\b.dll        ".NET Framework 4.5.2"
    

提交回复
热议问题