2 // System.Web.Compilation.CSCompiler
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2003 Ximian, Inc (http://www.ximian.com)
11 using System.CodeDom.Compiler;
12 using System.Collections;
13 using System.Collections.Specialized;
16 using System.Reflection;
17 using Microsoft.CSharp;
19 namespace System.Web.Compilation
23 static CodeDomProvider provider;
24 static ICodeCompiler compiler;
27 CompilerParameters options;
31 provider = new CSharpCodeProvider ();
32 compiler = provider.CreateCompiler ();
35 private CSCompiler (string filename, ArrayList assemblies)
37 this.filename = filename;
38 this.assemblies = assemblies;
39 options = new CompilerParameters ();
40 if (assemblies != null) {
41 StringCollection coll = options.ReferencedAssemblies;
42 foreach (string str in assemblies)
47 public Assembly GetCompiledAssembly ()
49 CompilerResults results = compiler.CompileAssemblyFromFile (options, filename);
50 if (results.NativeCompilerReturnValue != 0) {
51 StreamReader reader = new StreamReader (filename);
52 throw new CompilationException (filename, results.Errors, reader.ReadToEnd ());
55 return results.CompiledAssembly;
58 static public Assembly CompileCSFile (string file, ArrayList assemblies)
60 CSCompiler compiler = new CSCompiler (file, assemblies);
61 return compiler.GetCompiledAssembly ();
64 static public CodeDomProvider Provider {
65 get { return provider; }
68 static public ICodeCompiler Compiler {
69 get { return compiler; }