The Compiler-as-a-Service feature has been available in Mono for quite some time and there are signs that it might appear in .NET 5 or 6, but it's not available in .NET 4.
If you absolutely, positively, need to run on .NET (note that Mono runs on Windows just fine, so you don't actually lose anything by running Mono), one interesting option might be to investigate how hard it would be to port Mono.CSharp
to .NET. I mean, ultimately, at some point, it generates CIL bytecode which works exactly the same across all CLI implementations whether that be Mono, .NET, DotGNU, Rotor, Bartok or whatever.
Otherwise, your options are pretty much the same they have always been: generate files and call the commandline compier, use DLR trees, use lightweight code generation, use Reflection.Emit
, use CodeDOM, use CSharpCodeProvider
, create your own scripting language, host some other scripting language or host the DLR.
I'd probably go for the latter: hosting the DLR is absolutely easy and it gives you access to not only one but several good scripting languages (at the moment Ruby, Python, ECMAScript and Scheme) and in fact the user can use any DLR language they have installed on their machine.