Skip to content

Instantly share code, notes, and snippets.

@hansschmucker
Created September 4, 2014 08:58
Show Gist options
  • Save hansschmucker/f4031a37241d3d95e433 to your computer and use it in GitHub Desktop.
Save hansschmucker/f4031a37241d3d95e433 to your computer and use it in GitHub Desktop.
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