Search code examples
c#.netcompilationcsharpcodeprovider

How to compile c# code into memory?


I'm using Microsoft's CSharpCodeProvider to dynamically create and execute code.

Right now, it creates an assembly in a dll, located inside a temporary folder.

I want for it to create an assembly in memory without having to write it to a hard drive.

How do I do that?


Solution

  • I think you're just looking for CompilerParameters.GenerateInMemory.

    Set that to true for the compiler parameters you pass in when compiling, and it won't generate a file.