public static CompileResult CreateAssemblyWithRoslyn(FileRunnerSubmission submission, string workingDirectory) { var currentDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(workingDirectory); IEnumerable <int> x = null; var syntaxTree = CSharpSyntaxTree.ParseText(submission.Code); var assemblyName = submission.Id; var compilation = CSharpCompilation.Create(assemblyName, new[] { syntaxTree }, new MetadataReference[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), // mscorlib MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), // System MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), // System.Core MetadataReference.CreateFromFile(typeof(Point).Assembly.Location), // System.Drawing, MetadataReference.CreateFromFile(typeof(ValueTuple).Assembly.Location), // System.ValueTuple MetadataReference.CreateFromFile(SystemRuntimeDllPath), // System.Runtime (defines ValueType type), }, new CSharpCompilationOptions(OutputKind.ConsoleApplication)); var assemblyFilename = Path.Combine(workingDirectory, assemblyName + ".exe"); Directory.SetCurrentDirectory(currentDirectory); return(new CompileResult(compilation.Emit(assemblyFilename), assemblyFilename)); }
public static CompileResult CreateAssemblyWithRoslyn(FileRunnerSubmission submission, string workingDirectory, TimeSpan compilationTimeLimit) { var syntaxTree = CSharpSyntaxTree.ParseText(submission.Code); var assemblyName = submission.Id; var compilation = CSharpCompilation.Create( assemblyName, new[] { syntaxTree }, new MetadataReference[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), // mscorlib MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), // System MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), // System.Core MetadataReference.CreateFromFile(typeof(Point).Assembly.Location), // System.Drawing, MetadataReference.CreateFromFile(typeof(ValueType).Assembly.Location), // System.Runtime }, new CSharpCompilationOptions(OutputKind.ConsoleApplication)); var assemblyFilename = Path.Combine(workingDirectory, assemblyName + ".exe"); using (var cts = new CancellationTokenSource(compilationTimeLimit)) { var startTime = DateTime.Now; var emitResult = compilation.Emit(assemblyFilename, cancellationToken: cts.Token); return(new CompileResult(emitResult, assemblyFilename, DateTime.Now - startTime)); } }
public static CompilerResults CreateAssembly(FileRunnerSubmission submission) { var provider = new CSharpCodeProvider(new Dictionary<string, string> { { "CompilerVersion", "v4.0" } }); var compilerParameters = new CompilerParameters(UsesAssemblies) { GenerateExecutable = true, IncludeDebugInformation = true, WarningLevel = 4, }; var assembly = provider.CompileAssemblyFromSource(compilerParameters, submission.Code); return assembly; }
private static RunningResults GetDetails(string code, string input) { var model = new FileRunnerSubmission { Id = Utils.NewNormalizedGuid(), Code = code, Input = input, NeedRun = true }; var result = new SandboxRunner(model).RunCsc("."); Assert.IsNotNull(result); Console.WriteLine(result); return(result); }
public static CompilerResults CreateAssembly(FileRunnerSubmission submission) { var provider = new CSharpCodeProvider(new Dictionary <string, string> { { "CompilerVersion", "v4.0" } }); var compilerParameters = new CompilerParameters(UsesAssemblies) { GenerateExecutable = true, IncludeDebugInformation = true, WarningLevel = 4, }; var assembly = provider.CompileAssemblyFromSource(compilerParameters, submission.Code); return(assembly); }
public static CompileResult CreateAssemblyWithRoslyn(FileRunnerSubmission submission, string workingDirectory) { var currentDirectory = Directory.GetCurrentDirectory(); Directory.SetCurrentDirectory(workingDirectory); IEnumerable<int> x = null; var syntaxTree = CSharpSyntaxTree.ParseText(submission.Code); var assemblyName = submission.Id; var compilation = CSharpCompilation.Create(assemblyName, new[] { syntaxTree }, new MetadataReference[] { MetadataReference.CreateFromFile(typeof(object).Assembly.Location), // mscorlib MetadataReference.CreateFromFile(typeof(Uri).Assembly.Location), // System MetadataReference.CreateFromFile(typeof(Enumerable).Assembly.Location), // System.Core MetadataReference.CreateFromFile(typeof(Point).Assembly.Location), //System.Drawing }, new CSharpCompilationOptions(OutputKind.ConsoleApplication)); var assemblyFilename = Path.Combine(workingDirectory, assemblyName + ".exe"); Directory.SetCurrentDirectory(currentDirectory); return new CompileResult(compilation.Emit(assemblyFilename), assemblyFilename); }
private static RunningResults GetDetails(string code, string input) { var model = new FileRunnerSubmission { Id = Utils.NewNormalizedGuid(), Code = code, Input = input, NeedRun = true }; var result = new SandboxRunner(model).RunCsc60("."); Assert.IsNotNull(result); Console.WriteLine(result); return result; }