How to find out which version of the .NET Framework an executable needs to run?

.NetVersionExecutable

.Net Problem Overview


I've got an executable file, and I would like to know which version(s) of the Microsoft .NET Framework this file needs to be started.

Is there an easy way to find this information somewhere?

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

.Net Solutions


Solution 1 - .Net

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

  • open application with notepad appname.exe,
  • search for word framework,
  • repeat last search with F3 until .NET Framework,version=vX.Y shows up
  • 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.

update: Thought and Marcus suggested in comments that search term could also be netstandard or netframework

Solution 2 - .Net

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".

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

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:

.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:

.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.

Solution 3 - .Net

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

See the properties panel: enter image description here

Solution 4 - .Net

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:

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

Solution 5 - .Net

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.

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.

Solution 6 - .Net

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

Solution 7 - .Net

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.

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.

Solution 8 - .Net

You can obtain the .NET version of a file in Windows using Powershell. The following script;

$path=’.\’
$ErrorActionPreference = "SilentlyContinue"
$files=Get-ChildItem -Path $path -Recurse -include *.dll,*.exe
foreach($file in $files)
{
    $filename = $file.BaseName
    $version = $([System.Reflection.Assembly]::ReflectionOnlyLoadFrom($file.FullName).GetCustomAttributesData() |
                 select-object -ExpandProperty ConstructorArguments | 
                 select-object -ExpandProperty Value | 
                 select-string -Pattern '.NET')
    Write-Output "$filename,$version"
}

provides the following result; enter image description here

Note that the result extracted the .NET version for the exe files in that folder, but it will also do the same for a dll.

Solution 9 - .Net

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.

Solution 10 - .Net

On Linux/OSX/unix you can use:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSamView Question on Stackoverflow
Solution 1 - .NetAsain KujovicView Answer on Stackoverflow
Solution 2 - .NetScott DormanView Answer on Stackoverflow
Solution 3 - .NetDaniel A. WhiteView Answer on Stackoverflow
Solution 4 - .NettsandholView Answer on Stackoverflow
Solution 5 - .NetAndrew HareView Answer on Stackoverflow
Solution 6 - .NetSean BView Answer on Stackoverflow
Solution 7 - .NetVince FedorchakView Answer on Stackoverflow
Solution 8 - .NetMark WalkerView Answer on Stackoverflow
Solution 9 - .NetDenisView Answer on Stackoverflow
Solution 10 - .NetPierzView Answer on Stackoverflow