2

Is it possible for a .Net Framework 4.6.2 project to use System.Reflection.Emit to create a .Net Core or .Net Standard DLL file? What I have now is a project that generates a .Net Framework 4.0 DLL file. Can I change some setting somewhere so that the generated DLL file uses .Net Core or .Net Standard instead?

Edit: Here's an example. I got the following code from this page that covers the System.Reflection.Emit library.

    static void Main(string[] args)
    {
        AppDomain ad = AppDomain.CurrentDomain;
        AssemblyName am = new AssemblyName();
        am.Name = "TestAsm";
        AssemblyBuilder ab = ad.DefineDynamicAssembly(am, AssemblyBuilderAccess.Save);
        ModuleBuilder mb = ab.DefineDynamicModule("testmod", "TestAsm.exe");
        TypeBuilder tb = mb.DefineType("mytype", TypeAttributes.Public);
        MethodBuilder metb = tb.DefineMethod("hi", MethodAttributes.Public |
        MethodAttributes.Static, null, null);
        ab.SetEntryPoint(metb);

        ILGenerator il = metb.GetILGenerator();
        il.EmitWriteLine("Hello World");
        il.Emit(OpCodes.Ret);
        tb.CreateType();
        ab.Save("TestAsm.exe");
    }

When I run this code, it generates TestAsm.exe. When I open TestAsm.exe in my decompiler (JetBrains dotPeek), it shows that TestAsm.exe is "msil, .Net Framework v4.0, Debug"

How do I change this? My project is a .Net 4.6.2 project, so the generated EXE is not based on the generating project's framework version.

user2023861
  • 8,030
  • 9
  • 57
  • 86
  • 1
    I don't believe you can cross-compile with `Emit`... And 4.0 *is* the version of framework for 4.6.2 (you can check it by looking at properties of any of the system.* assemblies). – Alexei Levenkov Jan 10 '20 at 00:23

0 Answers0