You've already said you know how to do with with CodeDOM - why not just use that?
If you're happy with it being C# code, then CSharpCodeProvider
does an admirable job. If you're feeling more adventurous, you might want to consider Boo - read Ayende Rahien's book on building DSLs in Boo for more information and advice.
For an example of using CSharpCodeProvider
, you could download Snippy from my C# in Depth web site. Basically Snippy lets you type in a code snippet and run it, without bothering to declare a class etc. It doesn't do much more than build and run code, so it's a fairly handy example :)
For plenty more examples, search for CSharpCodeProvider on Stack Overflow. Here's a short but complete one - code for "hello world" is compiled and then executed.
using System;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
class Test
{
public static void Main(string[] args)
{
string code = @"
using System;
class CodeToBeCompiled
{
static void Main()
{
Console.WriteLine(""Hello world"");
}
}";
var codeProvider = new CSharpCodeProvider();
var parameters = new CompilerParameters
{
GenerateExecutable = true,
OutputAssembly = "Generated.exe"
};
var results = codeProvider.CompileAssemblyFromSource
(parameters, new[] { code });
results.CompiledAssembly.EntryPoint.Invoke(null, null);
}
}