Skip to content

Use mono cecil to read AssemblyInformation from a .NET assembly

License

Notifications You must be signed in to change notification settings

cjbush/assemblyinfo

 
 

Repository files navigation

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.

Powershell

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 via nuget

Install-Package assemblyinfo

Supported frameworks

  • NET 4.5.1
  • NET 4.5
  • NET 4.0
  • NET 3.5
  • NET 2.0

Examples

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);

License

MIT

About

Use mono cecil to read AssemblyInformation from a .NET assembly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PowerShell 65.8%
  • C# 34.2%