确定 dll 的 .NET Framework 版本
我有一个旧的 dll,它是针对 .NET 框架编译并部署的。我不确定它是针对哪个版本的 .NET 框架进行编译的。我想知道如何确定该 dll 是针对哪个版本的 .NET 框架进行编译的?我无法信任源代码,因为我相信它已升级到 Visual Studio 2008 并更改为 .NET Framework 版本 3.5。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(16)
在 PowerShell 中,您可以使用以下命令获取目标运行时:
我根据 Ben Griswold 的回答将其改编为 PowerShell。
如果您想知道 Visual Studio 中指定的目标框架版本,请使用:
您应该得到类似的信息
In PowerShell you can use the following to get the target runtime:
I adapted this to PowerShell from Ben Griswold's answer.
If you want to know the target framework version specified in Visual Studio, use:
You should get something like
dotPeek 是一个很棒的(免费)工具来显示此信息。
如果您在使用 Reflector 时遇到一些问题,那么这是一个不错的选择。
dotPeek is a great (free) tool to show this information.
If you are having a few issues getting hold of Reflector then this is a good alternative.
您可以使用 ILDASM...
并检查输出中的“元数据部分”。它会是这样的:
“版本”标签会告诉您.NET Framework 版本。在上面的例子中是 4.0.30319
You can use ILDASM...
and check for the 'Metadata section' in the output. It would be something like this:
The 'version' tag will tell you the .NET Framework version. In the above example it is 4.0.30319
将其加载到 Reflector 并查看它引用了什么?
例如:
Load it into Reflector and see what it references?
for example:
您有几个选择: 要以编程方式从托管代码中获取它,请使用 Assembly.ImageRuntimeVersion:
从命令行中,从 v2.0 开始,如果您双击“MANIFEST”并查找“,ildasm.exe 将显示它”元数据版本”。 确定映像的 CLR 版本
You have a few options: To get it programmatically, from managed code, use Assembly.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
使用 ILSpy http://ilspy.net/
开源、免费,绝对是一个选择,因为现在 Reflector 是付费的。
Use ILSpy http://ilspy.net/
open source, free, definitely an option since now reflector is paid.
只是简单地
Just simply
最简单的方法:只需在任何文本编辑器中打开 .dll。看最后一行之一:
对于 .Net 8.0,字符串略有更新
.NETCoreApp,Version=v8.0
The simplest way: just open the .dll in any text editor. Look at one of the last lines:
For .Net 8.0 the string is slightly updated
.NETCoreApp,Version=v8.0
通过 Visual Studio 的另一个选项,将对 DLL 的引用添加到任何项目,然后右键单击新引用并单击“属性”,您可以在运行时版本中看到您要查找的内容:
Yet another option via Visual Studio, add a reference to the DLL to any project, then right-clicking on the new reference and click Properties, you can see what you are looking for in Runtime version:
使用 ILDASM 反编译它,然后查看正在引用的 mscorlib 版本(应该几乎位于顶部)。
Decompile it with ILDASM, and look at the version of mscorlib that is being referenced (should be pretty much right at the top).
如果您有 JetBrains 的 dotPeek,则可以在 Assembly Explorer 中看到它。
If you have dotPeek from JetBrains, you can see it in Assembly Explorer.
我快速编写了这个 C# 控制台应用程序来执行此操作:
https://github.com/stuartjsmith/binarydetailer
只需传递一个目录作为参数,它就会尽力告诉您其中每个 dll 和 exe 的网络框架
I quickly wrote this C# console app to do this:
https://github.com/stuartjsmith/binarydetailer
Simply pass a directory as a parameter and it will do its best to tell you the net framework for each dll and exe in there
“Detect It Easy”也称为 DiE,是一个用于确定文件类型的程序。适用于 .dll 文件或其他 (.exe) 文件。绝对免费用于商业和非商业用途。
"Detect It Easy" also known as DiE is a program for determining types of files. Works with .dll files or other (.exe) files. Absolute free for commercial and non-commercial use.
使用“读取dll文本内容”的方式:
Using the "read the text contents of the dll" approach:
扩展此处的答案,如果存在依赖程序集,则可能会崩溃。如果您很幸运并且知道受抚养人在哪里(或者更幸运的是,在 GAC 中),那么这可能会有所帮助...
参考:https://weblog.west-wind.com/posts/2006/Dec/22/Reflection-on-Problem-Assemblies
Expanding on the answers here, this can blow up if there is a dependent assembly. If you're lucky and you know where the dependent is (or even luckier, it's in the GAC) then this may help ...
Reference: https://weblog.west-wind.com/posts/2006/Dec/22/Reflection-on-Problem-Assemblies
如果您使用的是 Linux 并且有单声道,我认为您可以使用 ikdasm 代替 ildasm.exe 。
我不太明白这个,所以不知道是否准确。但我做了一个简单的测试,编译了一个dll库,只改变了
。然后我在输出(bin)目录上运行这个:每个目标框架的结果都不同。
net8.0
netstandard2.1
net4.8
这个似乎只显示主要版本,所以:
5: Assembly: 1 instance void class [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::'.ctor'(System.String) [".NETFramework,Version=v4.8", {FrameworkDisplayName = ""}]
If you're on Linux and have mono, I think you can use
ikdasm
instead ofildasm.exe
.I don't really understand this, so I don't know if it's accurate. But I made a simple test compiling a dll library, changing only
<TargetFramework>
. Then I ran this on the output (bin) dir:The result is different for each target framework.
net8.0
netstandard2.1
net4.8
This one seems to show only major version, so:
5: Assembly: 1 instance void class [mscorlib]System.Runtime.Versioning.TargetFrameworkAttribute::'.ctor'(System.String) [".NETFramework,Version=v4.8", {FrameworkDisplayName = ""}]