This small library uses cecil to inspect MSIL code found in .NET assemblies
instead of Assembly.Load
which ensures that you do not have to load it's dependencies
beforehand. This is particularly useful if you just want to know what .NET target framework an
assembly is targeting without running the risk of catching an exception from Assembly.Load
because of a missing dependency.
A powershell version is available here. Please note that there's a limitation where you cannot differentiate between NET45 and NET451. This is because the Microsoft PE and COFF Specification does not reveal this information.
Install-Package assemblyinfo
- NET 4.5.1
- NET 4.5
- NET 4.0
- NET 3.5
- NET 2.0
Additional examples are available here
// Read from disk
AssemblyInfo.GetTargetFramework("myassembly.dll").IsEqualTo(TargetFramework.Net_2_0);
// Read from byte array
AssemblyInfo.GetTargetFramework(
File.ReadAllBytes("myassembly.dll")
).IsEqualTo(TargetFramework.Net_2_0);
// Read from stream
AssemblyInfo.GetTargetFramework(
new MemoryStream(File.ReadAllBytes("myassembly.dll"))
).IsEqualTo(TargetFramework.Net_2_0);
// Read from current assembly
AssemblyInfo.GetTargetFramework(
Assembly.GetExecutingAssembly()
).IsEqualTo(TargetFramework.Net_2_0);
// Determine minimum supported target framework
AssemblyInfo.GetTargetFramework(new List<string> {
"assembly1.dll",
"assembly2.dll"
}).IsGreaterThan(TargetFramework.Net_2_0);
// Determine minimum supported target framework
AssemblyInfo.GetTargetFramework(new List<string> {
"assembly1.dll",
"assembly2.dll"
}).IsLessThanOrEqualTo(TargetFramework.Net_4_5_1);
// Determine minimum supported target framework
AssemblyInfo.GetTargetFramework(new List<byte[]> {
File.ReadAllBytes("assembly1.dll"),
File.ReadAllBytes("assembly2.dll")
}).IsGreaterThanOrEqualTo(TargetFramework.Net_4_5_1);
MIT