确定 .NET Framework 的 dll 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3460982/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Determine .NET Framework version for dll
提问by mpenrow
I have an old dll that was compiled against the .NET framework and deployed. I am not sure which version of the .NET framework it was compiled against. I am wondering how I can determine which version of the .NET framework this dll was compiled against? I cannot trust the source code because I believe it has been upgraded to Visual Studio 2008 and changed to .NET framework version 3.5.
我有一个针对 .NET 框架编译并部署的旧 dll。我不确定它是针对哪个版本的 .NET 框架编译的。我想知道如何确定此 dll 是针对哪个版本的 .NET 框架编译的?我不能相信源代码,因为我相信它已升级到 Visual Studio 2008 并更改为 .NET 框架版本 3.5。
采纳答案by ParmesanCodice
回答by Swoogan
In PowerShell you can use the following to get the target runtime:
在 PowerShell 中,您可以使用以下命令获取目标运行时:
$path = "C:\Some.dll"
[Reflection.Assembly]::ReflectionOnlyLoadFrom($path).ImageRuntimeVersion
I adapted this to PowerShell from Ben Griswold's answer.
我根据Ben Griswold 的回答将其改编为 PowerShell 。
If you want to know the target framework version specified in Visual Studio, use:
如果您想知道 Visual Studio 中指定的目标框架版本,请使用:
$path = "C:\Some.dll"
[Reflection.Assembly]::ReflectionOnlyLoadFrom($path).CustomAttributes |
Where-Object {$_.AttributeType.Name -eq "TargetFrameworkAttribute" } |
Select-Object -ExpandProperty ConstructorArguments |
Select-Object -ExpandProperty value
You should get something like
你应该得到类似的东西
.NETFramework,Version=v4.5.2
.NETFramework,版本=v4.5.2
回答by wal
回答by Josh Stodola
You can use ILDASM...
您可以使用ILDASM...
ildasm.exe C:\foo.dll /metadata[=MDHEADER] /text /noil
and check for the 'Metadata section' in the output. It would be something like this:
并检查输出中的“元数据部分”。它会是这样的:
Metadata section: 0x424a5342, version: 1.1, extra: 0, version len: 12, version: v4.0.30319
元数据部分:0x424a5342,版本:1.1,额外:0,版本len:12,版本:v4.0.30319
The 'version' tag will tell you the .NET Framework version. In the above example it is 4.0.30319
'version' 标签会告诉你 .NET Framework 版本。在上面的例子中它是 4.0.30319
回答by Ben Griswold
You have a few options: To get it programmatically, from managed code, use Assembly.ImageRuntimeVersion:
您有几个选择: 要以编程方式从托管代码中获取它,请使用 Assembly.ImageRuntimeVersion:
Dim a As Assembly = Reflection.Assembly.ReflectionOnlyLoadFrom("C:\path\assembly.dll")
Dim s As String = a.ImageRuntimeVersion
From the command line, starting in v2.0, ildasm.exe will show it if you double-click on "MANIFEST" and look for "Metadata version". Determining an Image's CLR Version
从命令行,从 v2.0 开始,如果您双击“MANIFEST”并查找“元数据版本”,ildasm.exe 将显示它。确定图像的 CLR 版本
回答by Kat Lim Ruiz
Use ILSpy http://ilspy.net/
使用 ILSpy http://ilspy.net/
open source, free, definitely an option since now reflector is paid.
开源,免费,绝对是一个选择,因为现在反射器是付费的。
回答by stenly
Just simply
只是简单地
var tar = (TargetFrameworkAttribute)Assembly
.LoadFrom("yoursAssembly.dll")
.GetCustomAttributes(typeof(TargetFrameworkAttribute)).First();
回答by lingo_journey
回答by leppie
Decompile it with ILDASM, and look at the version of mscorlib that is being referenced (should be pretty much right at the top).
使用 ILDASM 对其进行反编译,然后查看所引用的 mscorlib 版本(应该在顶部)。


