如何找出可执行文件需要运行的。net框架的哪个版本?

时间:2022-02-25 13:16:20

I've got an executable file, and I would like to know which versions of the .NET framework this file needs to be started.

我有一个可执行文件,我想知道这个文件需要启动。net框架的哪个版本。

Is there an easy way to find this information somewhere?

有没有一种简单的方法可以找到这些信息?

(So far I tried ILDASM and DUMPBIN without any luck.)

(到目前为止,我尝试了ILDASM和DUMPBIN,没有任何运气。)

9 个解决方案

#1


51  

I think the closest you can reliably get is to determine what version of the CLR is required. You can do this by using ILDASM and looking at the "MANIFEST" node or Reflector and looking at the dissasembly view of the "Application.exe" node as IL. In both cases there is a comment that indicates the CLR version. In ILDASM, the comment is "// Metadata version" and in Reflector the comment is "Target Runtime Version".

我认为最可靠的方法是确定需要什么版本的CLR。您可以通过使用ILDASM并查看“清单”节点或反射器,并查看“应用程序”的无序视图来实现这一点。exe“节点为IL。在这两种情况下,都有一个注释指示CLR版本。在ILDASM中,注释是“//元数据版本”,在Reflector中,注释是“目标运行时版本”。

Here are examples for a .NET WinForms application named WindowsFormsApplication1.exe:

下面是一个名为WindowsFormsApplication1.exe的。net WinForms应用程序的示例:

ILDASM:

ILDASM:

// Metadata version: v2.0.50727
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly extern System
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}

Reflector:

反射器:

.module WindowsFormsApplication1.exe
.subsystem 0x0002
// MVID: {CA3D2090-16C5-4899-953E-4736D6BC0FA8}
// Target Runtime Version: v2.0.50727

You can also look at the list of referenced assemblies and look for the reference with the highest version number.

您还可以查看所引用程序集的列表,并查找具有最高版本号的引用。

Again, using ILDASM looking at the "MANIFEST" node data:

再次,使用ILDASM来查看“清单”节点数据:

.assembly extern System.Drawing
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 2:0:0:0
}
.assembly extern System.Core
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 3:5:0:0
}

And using Reflector, looking at the dissambly (still as IL) for each reference listed:

使用反射镜,查看不一致的(仍然作为IL)为每个参考列出:

.assembly extern System.Core
{
    .ver 3:5:0:0
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89)
}

By finding the reference with the highest version metadata you can determine what version of the Framework that reference came from, which would indicate that you need the same version of the Framework installed for the application to run. That being said, I wouldn't treat this as 100% reliable, but I don't think it will change any time soon.

通过查找具有最高版本元数据的引用,您可以确定引用的框架的版本,这表明您需要为应用程序运行安装的框架的相同版本。话虽如此,我不认为这是100%可靠的,但我认为它不会很快改变。

#2


26  

Using Notepad, three decades old, 200kb in size, preinstalled tool:

使用记事本,30年前,200kb大小,预装工具:

  • open application with notepad appname.exe,
  • 使用记事本应用程序打开应用程序。
  • search for word "framework",
  • 搜索词“框架”,
  • repeat last search with F3 until .NET Framework,version=vX.Y shows up
  • 使用F3重复最后一次搜索,直到。net Framework,version=vX。Y出现
  • if nothing found (versions below 3.0) search for v2. ... still 100 times easier then installing gigabytes of dot net analyzer tools and garbage studios.
  • 如果没有发现(3.0以下版本)搜索v2。相比之下,安装千兆字节的dot net分析器工具和垃圾处理工具要容易上100倍。

Any other editor/viewer can open binaries too, like Notepad++ or totalCommander's great text/hex viewer lister.

任何其他编辑器/查看器也可以打开二进制文件,比如Notepad+或totalCommander的伟大文本/十六进制查看器lister。

#3


26  

A more simplified approach would be to use dotPeek and see what shows up in the tree.

更简单的方法是使用dotPeek,看看树中出现了什么。

See the properties panel: 如何找出可执行文件需要运行的。net框架的哪个版本?

看到properties面板:

#4


17  

You can now use ILSpy to examine the target framework of an assembly. After loading the assembly, click on the root of the assembly node, and you can find the information under the TargetFramework declaration:

现在可以使用ILSpy来检查程序集的目标框架。加载程序集后,单击程序集节点的根节点,可以在TargetFramework声明下找到信息:

[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

#5


15  

From code you can use Assembly.ImageRuntimeVersion but by looking at the file probably the best thing to do would be to use reflector and see which version of mscorlib is being referenced.

从代码中可以使用汇编。ImageRuntimeVersion但是通过查看文件,最好的方法是使用reflector并查看正在引用哪个版本的mscorlib。

Edit: Even better would be to use ildasm, open your assembly and then view the manifest for the assembly. The first line of the manifest will tell you the exact version of CLR that the assembly was built for.

编辑:最好是使用ildasm,打开程序集,然后查看程序集的清单。清单的第一行将告诉您构建程序集的确切CLR版本。

#6


10  

You can use a tool called CorFlags.exe. It has been around since .NET 2.0, and I know for sure that it is included in the Windows SDK 7.0. By default (on Windows XP Pro) it is installed to C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\CorFlags.exe. Provide it with the file path to a managed module (without any other command-line flags) to display its header information, which includes the version.

你可以使用一个叫做CorFlags.exe的工具。它从。net 2.0开始就存在了,我确信它包含在Windows SDK 7.0中。在默认情况下(在Windows XP专业版)安装C:\Program Files\Microsoft sdk \ Windows \ v7.0A \ bin \ CorFlags.exe。为它提供到托管模块的文件路径(没有任何其他命令行标志),以显示它的头信息(包括版本)。

Keep in mind that this utility is designed to modify the PE32 header of a module, so don't use any of the flags until you read the documentation carefully.

请记住,这个实用程序的设计目的是修改模块的PE32头,所以在仔细阅读文档之前,不要使用任何标志。

#7


7  

From the command line: find "Framework" MyApp.exe

从命令行:查找“Framework”MyApp.exe

#8


2  

Or you can just find out which reference of System.Core it has. That will tell you the .NET Framework version this app is using. For 2.0 the version of System.Core will be 2.0.xxx.xxx. For 3.5 the version will be 3.5.xxx.xxx, etc.

或者你可以找出系统的引用。核心。这将告诉你这个应用正在使用的。net框架版本。对于2.0版本的系统。核心将2.0.xxx.xxx。3.5版为3.5.xxx。xxx等。

#9


0  

On Linux/OSX/unix you can use:

在Linux/OSX/unix上,您可以使用:

strings that_app.exe | grep 'v2.\|Framework'

#1


51  

I think the closest you can reliably get is to determine what version of the CLR is required. You can do this by using ILDASM and looking at the "MANIFEST" node or Reflector and looking at the dissasembly view of the "Application.exe" node as IL. In both cases there is a comment that indicates the CLR version. In ILDASM, the comment is "// Metadata version" and in Reflector the comment is "Target Runtime Version".

我认为最可靠的方法是确定需要什么版本的CLR。您可以通过使用ILDASM并查看“清单”节点或反射器,并查看“应用程序”的无序视图来实现这一点。exe“节点为IL。在这两种情况下,都有一个注释指示CLR版本。在ILDASM中,注释是“//元数据版本”,在Reflector中,注释是“目标运行时版本”。

Here are examples for a .NET WinForms application named WindowsFormsApplication1.exe:

下面是一个名为WindowsFormsApplication1.exe的。net WinForms应用程序的示例:

ILDASM:

ILDASM:

// Metadata version: v2.0.50727
.assembly extern mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly extern System
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}

Reflector:

反射器:

.module WindowsFormsApplication1.exe
.subsystem 0x0002
// MVID: {CA3D2090-16C5-4899-953E-4736D6BC0FA8}
// Target Runtime Version: v2.0.50727

You can also look at the list of referenced assemblies and look for the reference with the highest version number.

您还可以查看所引用程序集的列表,并查找具有最高版本号的引用。

Again, using ILDASM looking at the "MANIFEST" node data:

再次,使用ILDASM来查看“清单”节点数据:

.assembly extern System.Drawing
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 2:0:0:0
}
.assembly extern System.Core
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 3:5:0:0
}

And using Reflector, looking at the dissambly (still as IL) for each reference listed:

使用反射镜,查看不一致的(仍然作为IL)为每个参考列出:

.assembly extern System.Core
{
    .ver 3:5:0:0
    .publickeytoken = (B7 7A 5C 56 19 34 E0 89)
}

By finding the reference with the highest version metadata you can determine what version of the Framework that reference came from, which would indicate that you need the same version of the Framework installed for the application to run. That being said, I wouldn't treat this as 100% reliable, but I don't think it will change any time soon.

通过查找具有最高版本元数据的引用,您可以确定引用的框架的版本,这表明您需要为应用程序运行安装的框架的相同版本。话虽如此,我不认为这是100%可靠的,但我认为它不会很快改变。

#2


26  

Using Notepad, three decades old, 200kb in size, preinstalled tool:

使用记事本,30年前,200kb大小,预装工具:

  • open application with notepad appname.exe,
  • 使用记事本应用程序打开应用程序。
  • search for word "framework",
  • 搜索词“框架”,
  • repeat last search with F3 until .NET Framework,version=vX.Y shows up
  • 使用F3重复最后一次搜索,直到。net Framework,version=vX。Y出现
  • if nothing found (versions below 3.0) search for v2. ... still 100 times easier then installing gigabytes of dot net analyzer tools and garbage studios.
  • 如果没有发现(3.0以下版本)搜索v2。相比之下,安装千兆字节的dot net分析器工具和垃圾处理工具要容易上100倍。

Any other editor/viewer can open binaries too, like Notepad++ or totalCommander's great text/hex viewer lister.

任何其他编辑器/查看器也可以打开二进制文件,比如Notepad+或totalCommander的伟大文本/十六进制查看器lister。

#3


26  

A more simplified approach would be to use dotPeek and see what shows up in the tree.

更简单的方法是使用dotPeek,看看树中出现了什么。

See the properties panel: 如何找出可执行文件需要运行的。net框架的哪个版本?

看到properties面板:

#4


17  

You can now use ILSpy to examine the target framework of an assembly. After loading the assembly, click on the root of the assembly node, and you can find the information under the TargetFramework declaration:

现在可以使用ILSpy来检查程序集的目标框架。加载程序集后,单击程序集节点的根节点,可以在TargetFramework声明下找到信息:

[assembly: TargetFramework(".NETFramework,Version=v4.5", FrameworkDisplayName = ".NET Framework 4.5")]

#5


15  

From code you can use Assembly.ImageRuntimeVersion but by looking at the file probably the best thing to do would be to use reflector and see which version of mscorlib is being referenced.

从代码中可以使用汇编。ImageRuntimeVersion但是通过查看文件,最好的方法是使用reflector并查看正在引用哪个版本的mscorlib。

Edit: Even better would be to use ildasm, open your assembly and then view the manifest for the assembly. The first line of the manifest will tell you the exact version of CLR that the assembly was built for.

编辑:最好是使用ildasm,打开程序集,然后查看程序集的清单。清单的第一行将告诉您构建程序集的确切CLR版本。

#6


10  

You can use a tool called CorFlags.exe. It has been around since .NET 2.0, and I know for sure that it is included in the Windows SDK 7.0. By default (on Windows XP Pro) it is installed to C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\CorFlags.exe. Provide it with the file path to a managed module (without any other command-line flags) to display its header information, which includes the version.

你可以使用一个叫做CorFlags.exe的工具。它从。net 2.0开始就存在了,我确信它包含在Windows SDK 7.0中。在默认情况下(在Windows XP专业版)安装C:\Program Files\Microsoft sdk \ Windows \ v7.0A \ bin \ CorFlags.exe。为它提供到托管模块的文件路径(没有任何其他命令行标志),以显示它的头信息(包括版本)。

Keep in mind that this utility is designed to modify the PE32 header of a module, so don't use any of the flags until you read the documentation carefully.

请记住,这个实用程序的设计目的是修改模块的PE32头,所以在仔细阅读文档之前,不要使用任何标志。

#7


7  

From the command line: find "Framework" MyApp.exe

从命令行:查找“Framework”MyApp.exe

#8


2  

Or you can just find out which reference of System.Core it has. That will tell you the .NET Framework version this app is using. For 2.0 the version of System.Core will be 2.0.xxx.xxx. For 3.5 the version will be 3.5.xxx.xxx, etc.

或者你可以找出系统的引用。核心。这将告诉你这个应用正在使用的。net框架版本。对于2.0版本的系统。核心将2.0.xxx.xxx。3.5版为3.5.xxx。xxx等。

#9


0  

On Linux/OSX/unix you can use:

在Linux/OSX/unix上,您可以使用:

strings that_app.exe | grep 'v2.\|Framework'