Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Source for a minimal C# compiler for use in batch files see https://gist.github.com/hansschmucker/820d3bdeca34c665b77a
$opt = New-Object System.CodeDom.Compiler.CompilerParameters;
$opt.GenerateInMemory = $true;
$cr = [System.CodeDom.Compiler.CodeDomProvider]::CreateProvider("CSharp").CompileAssemblyFromSource($opt, "public class App { public static void Main() { "+ $input+" } }");
if($cr.CompiledAssembly){
$obj = $cr.CompiledAssembly.CreateInstance("App");
$obj.GetType().GetMethod("Main").Invoke($obj, $null);
}else{
$cr.errors;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment