Created
September 4, 2014 08:58
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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