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.
-
4Possible duplicate of [How to find out which version of the .NET Framework an executable needs to run?](http://stackoverflow.com/questions/325918/how-to-find-out-which-version-of-the-net-framework-an-executable-needs-to-run) – sirdank Dec 02 '15 at 16:53
15 Answers
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
-
4This answer is the most helpful. All Windows OSes after 2003 support Powershell. A shell giving immediate feedback, not requiring any additional application support as many of the other answers suggest. Great for a "one off" check of a dll. you're the man @swoogan. – Nathan McCoy Jul 06 '15 at 11:17
-
2I did this for a DLL I built with a TargetFrameworkVersion of v3.5, and it returned v2.0.50727. What am I missing? – BHSPitMonkey Jun 11 '16 at 00:12
-
6@BHSPitMonkey there have only really been 4 runtime versions: 1.0, 1.1, 2.0 and 4.0. .NET 3.0 and 3.5 compile to CLR version 2.0. https://msdn.microsoft.com/en-us/library/bb822049(v=vs.110).aspx – Swoogan Jun 12 '16 at 18:08
-
-
2This script only provides RuntimeVersion, question is about TargetFrameworkversion. Effectively for all assemblies compiled against 2.0,3.0,3.5 this script shows the Runtime version as 2.0.0.0 – Kiran Vedula Apr 04 '17 at 20:41
-
@KiranVedula as I specified, I adapted this from another answer. However, you make a good point. I updated the answer to add the TargetFrameworkVersion. – Swoogan Apr 04 '17 at 21:07
-
4For me the ReflectionOnlyLoadFrom returns the ImageRuntimeVersion but zero CustomAttributes. Using LoadFrom instead of ReflectionOnlyLoadFrom gives the expected result. Any reason? PSVersion 5.1.16299.251 CLRVersion 4.0.30319.42000 – Bernard Vander Beken Apr 10 '18 at 07:12
-
2Looks like my assembly does not have "TargetFrameworkAttribute". It does have `ImageRuntimeVersion`. But I want the target framework version for which a binary was built for. What could be wrong? – Shameel Mohamed Nov 20 '18 at 15:00
-
I also got nothing from ReflectionOnlyLoadFrom and "LoadFrom" fixed it. I'm guessing it's because the DLLs are dotnet standard, and maybe that doesn't support reflection? – user1169420 Sep 14 '20 at 22:07
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.

- 17,409
- 8
- 74
- 109
-
4FYI, I switched from DotPeek to JustDecompile because of one issue: if you select "specific version = false," DotPeek showed an empty version, and JustDecompile shows the correct version. Made it worth switching for me. – ashes999 May 15 '13 at 19:17
-
Great - did exactly what I've wanted without install a trial for Reflector. – bernhardrusch Jan 27 '16 at 09:55
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

- 3,037
- 1
- 34
- 44

- 81,538
- 47
- 180
- 227
-
3What am I looking for here? Does this mean .NET 4.0? `// Metadata section: 0x424a5342, version: 1.1, extra: 0, version len: 12, versio n: v4.0.30319` – PeterX Oct 29 '13 at 08:41
-
Yes, for .NET 2 I get the following: // Metadata section: 0x424a5342, version: 1.1, extra: 0, version len: 12, version: v2.0.50727 – Simon Jul 28 '15 at 20:44
-

- 17,409
- 8
- 74
- 109

- 5,017
- 1
- 23
- 20
-
1My idea too, but knowing reflector, it will probably complain, and give it a nice non-descript error icon. – leppie Aug 11 '10 at 17:15
-
@leppie Shouldn't be a problem, even if it's .NET 1.1. Just change your default assembly list. – ParmesanCodice Aug 11 '10 at 17:17
-
Your answer is very helpful, but I advise not to rely on it blindly -- yesterday I spent too much time on my own project which was targeted for .Net 4.0, reported by Reflector to use .Net 4.0.3, and required to use .Net 4.5 by Windows :-) I don't know any method to verify this on project other than with sources -- see here: http://stackoverflow.com/questions/13214503/target-net-4-0-but-net-4-5-is-required – greenoldman Feb 04 '15 at 07:17
-
4You can also use the free, open-source alternative [ILSpy](http://ilspy.net/) as [noted](http://stackoverflow.com/a/25123275/2822719) by Kat Lim Ruiz. – Marcus Mangelsdorf Feb 02 '16 at 10:18
-
This answer worked for me: https://stackoverflow.com/a/3461027/2961177. – ckkkitty Nov 01 '17 at 17:02
You have a few options: To get it programmatically, from managed code, use Assembly.ImageRuntimeVersion:
Dim a As Assembly = Reflection.Assembly.ReflectionOnlyLoadFrom("C:\path\assembly.dll")
Dim s As String = a.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

- 17,793
- 14
- 58
- 60
Use ILSpy http://ilspy.net/
open source, free, definitely an option since now reflector is paid.

- 2,425
- 2
- 26
- 32
Just simply
var tar = (TargetFrameworkAttribute)Assembly
.LoadFrom("yoursAssembly.dll")
.GetCustomAttributes(typeof(TargetFrameworkAttribute)).First();
-
1I don't know why this has been downvoted, but I can run the snippet (a reference to System.Runtime.Versioning is needed) and successfully get the output (this is from LINQPad): TypeId typeof (TargetFrameworkAttribute) FrameworkName .NETFramework,Version=v4.0 FrameworkDisplayName .NET Framework 4 – Sudhanshu Mishra May 27 '14 at 10:41
-
This code doesn't retrieve the full version of the framework. "4.0" is good to know, but "v4.0.30319" would be more useful if you were, say, trying to get to RegAsm.exe. The more complete version information can be found in: string tar = Assembly.LoadFrom(@"myAssembly.dll").ImageRuntimeVersion; – Martin Dec 01 '17 at 15:21
-
This seems like the right approach, is there any circumstances where an assembly might not have this attribute applied? I've tested it with a .NET Core assembly and it correctly reports netcore and the version number. – Adam Naylor Apr 21 '18 at 08:54
-
This does not work for me. The `GetCustomAttributes` does not have a `TargetFrameworkAttribute`. But ImageRuntimeVersion works fine though, it retrieves the right CLR the binary was built for. I need the target framework version for which it was built. – Shameel Mohamed Nov 20 '18 at 07:46
-
It is far more complicated than that. This answer only works for .NET Framework 4.x and compiled by Microsoft C# compilers. It does not apply to the actual question. – Lex Li Jan 31 '23 at 09:42
-
@LexLi you need to understand that this question is 12yrs old and .net 4 was the latest one running at that time. The answer is relative to the time of question was raised. – st35ly Feb 05 '23 at 23:31
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:

- 15,147
- 6
- 86
- 135

- 653
- 1
- 8
- 22
-
I think this question is not asking about when a DLL is referenced in Visual Studio, but any ol' .NET DLL you find lying around on your PC. – ashes999 May 15 '13 at 19:18
-
7This answer indicates that you can add a reference to any ol' .NET DLL you find lying around on your PC, and one of the properties of the item under the References corresponding to that DLL is the "Runtime Version". – ALEXintlsos Sep 19 '13 at 19:43
-

- 341
- 3
- 7
-
-
2
-
1@Sisir There's no such thing as ".NET 3.0" - I assume you meant to say _.NET Core 3.x_ instead? (as not to get confused by 2006's _.NET Framework 3.0_ which confusingly actually ran on the .NET Framework 2.0 CLR) – Dai Jan 22 '22 at 09:35
-
I used this approach for my answer below. I only handled .NETFramework and .NETCoreApp but it is working for what I need. https://stackoverflow.com/a/72144367/635195 – Derek May 06 '22 at 16:02
Decompile it with ILDASM, and look at the version of mscorlib that is being referenced (should be pretty much right at the top).

- 115,091
- 17
- 196
- 297
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

- 431
- 4
- 8
-
Gives good detailed info; it's a command-line app; you have to pass it the directory name on the command-line. – philu Jun 24 '20 at 06:05
"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.

- 426
- 5
- 7
Using the "read the text contents of the dll" approach:
private static readonly Regex CompiledNetCoreRegex = new Regex(@".NETCoreApp,Version=v[0-9\.]+", RegexOptions.Compiled);
private static readonly Regex CompiledNetFrameworkRegex = new Regex(@".NETFramework,Version=v[0-9\.]+", RegexOptions.Compiled);
// You can define other methods, fields, classes and namespaces here
public string GetTargetFramework(FileInfo dll)
{
string contents = File.ReadAllText(dll.FullName);
Match match = CompiledNetCoreRegex.Match(contents);
if (match.Success)
{
return match.Value;
}
match = CompiledNetFrameworkRegex.Match(contents);
if (match.Success)
{
return match.Value;
}
return "unable to compute target framework";
}

- 7,615
- 5
- 33
- 58
-
I had to create a tool that finds out witch applications were built targeting an out of support .Net (core) framework. This method does what it should do. Looping through a whole directory, it gave me a list of all used .Net frameworks. Helped a lot :) – AlexK Apr 16 '23 at 15:23
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 ...
using System.Reflection;
using System.Runtime.Versioning;
// ...
{
AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve += new ResolveEventHandler(CurrentDomain_ReflectionOnlyAssemblyResolve);
var asm = System.Reflection.Assembly.LoadFrom(@"C:\Codez\My.dll");
var targetFrameAttribute = asm.GetCustomAttributes(true).OfType<TargetFrameworkAttribute>().FirstOrDefault();
targetFrameAttribute.Dump();
}
Assembly CurrentDomain_ReflectionOnlyAssemblyResolve(object sender, ResolveEventArgs args)
{
var name = args.Name;
if (name.StartsWith("Depends"))
return System.Reflection.Assembly.ReflectionOnlyLoadFrom(@"C:\Codez\Depends.dll");
return System.Reflection.Assembly.ReflectionOnlyLoad(args.Name);
}
Reference: https://weblog.west-wind.com/posts/2006/Dec/22/Reflection-on-Problem-Assemblies

- 8,578
- 7
- 65
- 114