Blog   |   Articles   |   Downloads   |   .NET   |   About   |   Contact


Back To


Compiling C# on the Fly

Here is some code I wrote to support compiling C# code on-the-fly.  E.g. you generate some source code at runtime, compile it right then and there, and then call the compiled classes.

This version keeps the resulting assembly in memory.  If you want to put the assembly on disk, see Microsoft.CSharp.Compiler in the .NET framework.

You can download the code, including NUnit tests, here.

 Note that you will need to edit the test file, see comments marked
 "***************"
in the file.)

Other links:

A discussion of this approach on Joel on Software.


Page History: Created 20 Jan 04
                                                                                                                                                                                                                                                                                                           
Copyright (c) 2003-2006, John Rusk.