Compile code at runtime?

  • Thread starter Thread starter Adam Clauss
  • Start date Start date
A

Adam Clauss

OK, I just ran across a program that did this and I am wondering is this
something they coded in themselves, or is there already helper classes, etc
available to assist in this.

The application compiles many C# files at runtime and then uses them.
How easy/hard is it to do such a thing?

Thanks
 
Adam Clauss said:
The application compiles many C# files at runtime and then uses them.
How easy/hard is it to do such a thing?

Hi. Use System.CodeDom.Compiler.ICodeCompiler to instantiate the compiler
you want, eg C# or VB.NET, add references using
System.CodeDom.Compiler.CompilerParameters.Parameters.ReferencedAssemblies.A
dd(), then compile it using
System.CodeDom.Compiler.CompileAssemblyFromSource().

There's a few details to take care of that I've omitted but it's not too
bad.

-- Alan
 
Back
Top