Determine .NET Framework version for dll
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.
Solution 1:
In PowerShell you can use the following to get the target runtime:
$path = "C:\Some.dll"
[Reflection.Assembly]::ReflectionOnlyLoadFrom($path).ImageRuntimeVersion
I adapted this to PowerShell from Ben Griswold's answer.
If you want to know the target framework version specified in Visual Studio, use:
$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
Solution 2:
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.
Solution 3:
Load it into Reflector and see what it references?
for example:
Solution 4:
You can use 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
The 'version' tag will tell you the .NET Framework version. In the above example it is 4.0.30319