How can I create dynamic assemblies and save them to disk using .NET 5 or later?

237 views Asked by At

I am trying to use AssemblyBuilder to create dynamic assemblies and save them in .NET 5,6,7

// Create the dynamic assembly
var builder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("DynamicAssembly"), AssemblyBuilderAccess.Run);

It seems AssemblyBuilderAccess now lacks the RunAndSave value, probably it is intentional to prevent persisting dynamically generated code (or was the deeply Windows dependent code of emit the issue?), anyway, I am wondering that there is an other mode or workaround.

Question

How can I create dynamic assemblies and save them to disk using .NET 5 or later?

1

There are 1 answers

0
mainmind83 On

There is no official implementation yet, but it looks like there will be one:

There are also some other alternatives: