private Assembly CreateAsmExecutor(string script, out string errorMsg) { errorMsg = null; var assemblyName = _scriptHash; var sourceTree = CSharpSyntaxTree.ParseText(script, path: Path.Combine(_beimingForceConfig.AppLibPath, assemblyName + ".cs"), encoding: Encoding.UTF8); var compilation = CSharpCompilation.Create(assemblyName, new[] { sourceTree }, _metadataReferences[_applicationName], new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithOptimizationLevel( OptimizationLevel.Release)); Assembly assembly; using (var assemblyStream = new MemoryStream()) { using (var pdbStream = new MemoryStream()) { var emitResult = compilation.Emit(assemblyStream, pdbStream); if (emitResult.Success) { var assemblyBytes = assemblyStream.GetBuffer(); var pdbBytes = pdbStream.GetBuffer(); assembly = Assembly.Load(assemblyBytes, pdbBytes); if (_scriptCommon) { SaveAssembly(assemblyName, assemblyBytes); } _compiled = true; } else { foreach (var item in emitResult.Diagnostics) { CompileErrorMessage.Add(item.ToString()); Console.WriteLine(item); } _compiled = false; return(null); } } } return(assembly); }
CompileErrorMessage IErrorMessageTransformer.Transform(CompileErrorMessage msg) { return(new CompileErrorMessage(msg.Line, msg.Col, msg.EndCol, msg.Message)); }