如何检查编译 DLL 文件的 .NET Framework 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4449493/
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
How do I check the version of the .NET Framework that a DLL file was compiled against?
提问by truthseeker
Possible Duplicate:
Determine framework (CLR) version of assembly
可能的重复:
确定程序集的框架 (CLR) 版本
I have a library/DLL file which is compiled in the .NET Framework.
我有一个在 .NET Framework 中编译的库/DLL 文件。
Now (without any coding) I would like to check the .NET Framework version which was used to compile this library. I need to know was it 2.0, 3.5, or 4.0. Is there any tool that help me to achieve this? (I know that it should be compiled under version 4.0 of the Framework, but I need to be 100% sure that version 4.0 of the Framework was used).
现在(没有任何编码)我想检查用于编译这个库的 .NET Framework 版本。我需要知道它是 2.0、3.5 还是 4.0。是否有任何工具可以帮助我实现这一目标?(我知道它应该在 Framework 4.0 版下编译,但我需要 100% 确定使用的是 Framework 4.0 版)。
回答by Daniel Dolz
You must use ILDASM. you double click the manifest and you get
您必须使用 ILDASM。你双击清单,你得到
// Metadata version: v2.0.50727
// 元数据版本:v2.0.50727
or
或者
// Metadata version: v4.0.30319
// 元数据版本:v4.0.30319
Framework 3.0 and 3.5 are not really new releases of the CLR, so you will keep having V2.0. At most, you can guess which framework you will need by cheching the dependencies. Some dlls are available only in 3.5, but if you manually copy them in a 2.0 only PC the app will work. Check C:\windows\Microsoft.NEt\Framework and you will find them in their according folder.
Framework 3.0 和 3.5 并不是 CLR 的真正新版本,因此您将继续使用 V2.0。最多,您可以通过检查依赖项来猜测您将需要哪个框架。某些 dll 仅在 3.5 中可用,但如果您在仅 2.0 的 PC 中手动复制它们,该应用程序将起作用。检查 C:\windows\Microsoft.NEt\Framework,您会在相应的文件夹中找到它们。
Hope this helps
希望这可以帮助
回答by Brosto
If you have it as a reference in a project. You should be able to look at the Runtime version under properties for that reference. No coding required =-)
如果您将其作为项目中的参考。您应该能够在该参考的属性下查看运行时版本。无需编码 =-)


回答by Chris Taylor
Use ILDASMor Reflectorto inspect the assembly manifest and see the version of the System.* assemblies that where referenced.
使用ILDASM或Reflector检查程序集清单并查看所引用的 System.* 程序集的版本。
For example, using ILDASM to view the manifest of a .NET assembly I can see that this was built targeting Framework 1.1
例如,使用 ILDASM 查看 .NET 程序集的清单,我可以看到这是针对 Framework 1.1 构建的
// Metadata version: v1.1.4322
.assembly extern mscorlib
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 1:0:5000:0
}
.assembly extern System.Web
{
.publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A ) // .?_....:
.ver 1:0:5000:0
}
.assembly extern System
{
.publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) // .z\V.4..
.ver 1:0:5000:0
}
.assembly extern ICSharpCode.SharpZipLib
{
.publickeytoken = (1B 03 E6 AC F1 16 4F 73 ) // ......Os
.ver 0:84:0:0
}
.assembly ReverseProxy
{
// --- The following custom attribute is added automatically, do not uncomment -------
// .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool,
// bool) = ( 01 00 00 01 00 00 )
.hash algorithm 0x00008004
.ver 0:0:0:0
}
.module ReverseProxy.dll
// MVID: {3F1B8B81-1B8F-4DD7-A71F-FD019C095F25}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003 // WINDOWS_CUI
.corflags 0x00000001 // ILONLY
// Image base: 0x010A0000
回答by Cody Gray
I would use Reflection:
我会使用反射:
Assembly a = Assembly.ReflectionOnlyLoadFrom("C:\library.dll");
Console.WriteLine(a.ImageRuntimeVersion);
But, I'm a programmer. I don't know how to determine these types of things "without any coding".
但是,我是一名程序员。我不知道如何“没有任何编码”地确定这些类型的东西。

