(string script, List<Assembly> references, string assemblyPath)
| 52 | } |
| 53 | |
| 54 | public static Assembly CompileBooAssembly(string script, List<Assembly> references, string assemblyPath) { |
| 55 | |
| 56 | #if(NET40 || NET45 || NET472) |
| 57 | |
| 58 | //We need to supply custom CompilerParameters to turn of adding default references. |
| 59 | //There is a bug in EmitAssembly that forces a permission check of destination assembly folder |
| 60 | //not to be performed and always resort to the AppDomain folder as the output location instead |
| 61 | BooCompiler compiler = new BooCompiler(new CompilerParameters(false)); |
| 62 | compiler.Parameters.Input.Add(new StringInput(RandomString(10), script)); |
| 63 | compiler.Parameters.OutputType = CompilerOutputType.Library; |
| 64 | compiler.Parameters.Debug = false; |
| 65 | compiler.Parameters.Checked = false; |
| 66 | compiler.Parameters.GenerateInMemory = true; |
| 67 | compiler.Parameters.OutputAssembly = assemblyPath; |
| 68 | compiler.Parameters.Pipeline = new CompileToFile (); |
| 69 | compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("System", true)); |
| 70 | compiler.Parameters.References.Add(compiler.Parameters.LoadAssembly("System.Runtime", true)); |
| 71 | |
| 72 | foreach (Assembly reference in references) { |
| 73 | compiler.Parameters.References.Add(reference); |
| 74 | } |
| 75 | |
| 76 | CompilerContext context = compiler.Run(); |
| 77 | |
| 78 | if (context.GeneratedAssembly != null) { |
| 79 | |
| 80 | |
| 81 | return context.GeneratedAssembly; |
| 82 | } else { |
| 83 | string compilerErrors = ""; |
| 84 | foreach (CompilerError error in context.Errors) |
| 85 | compilerErrors += error; |
| 86 | |
| 87 | throw new ArgumentException(compilerErrors, "script"); |
| 88 | } |
| 89 | #else |
| 90 | throw new NotImplementedException("Not supported under .NET 3.5 or below"); |
| 91 | #endif |
| 92 | } |
| 93 | } |
| 94 | } |
nothing calls this directly
no test coverage detected