0

Nowadays, .NET applications can be created, among others, with .NET Core and with the full .NET framework.

Both .NET Core and the full .NET Framework uses assembly files (dll files) to package the application.

Now given an assembly file loaded in a C# program via Reflection, how to know which environment(.NET Core, Full Framework...) it is targeting?

UPDATE

This turned out to be a duplicate question, I wanted to highlight the most helpful answer in the pre-existing question:

   Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath("Lib.dll");

   var targetFrwrk = assembly.GetCustomAttribute<TargetFrameworkAttribute>().FrameworkName;

The TargetFrameworkAttribute.FrameworkName property contains the name of the target framework. For example: .NETStandard,Version=v1.6 or .NETFramework,Version=v4.5.2 .

Community
  • 1
  • 1
Chedy2149
  • 2,821
  • 4
  • 33
  • 56
  • 5
    Runtimes don't build assemblies, compilers do. Those are under no obligation to record the framework they were using (nor is that generally useful information, nor for that matter does a compiler need to run any managed code at all). The linked question may be an appropriate duplicate if you want to know what framework an assembly is natively targeting. Otherwise, I can't help but wonder why you think you need to know. – Jeroen Mostert Apr 13 '17 at 13:07
  • @JeroenMostert Looks like he updated the question to clarify "targeting" was what was meant. – AaronLS Apr 13 '17 at 16:08
  • @JeroenMostert thank you for your clarifications. – Chedy2149 Apr 13 '17 at 20:31

0 Answers0