List <string> referenced_assemblies;
Dictionary <string, string> resource_files;
TempFileCollection temp_files;
- string virtual_path;
//TODO: there should be a Compile () method here which is where all the compilation exceptions are thrown from.
internal AssemblyBuilder (CodeDomProvider provider)
internal AssemblyBuilder (string virtualPath, CodeDomProvider provider)
{
this.provider = provider;
- this.virtual_path = virtualPath;
units = new List <CodeCompileUnit> ();
temp_files = new TempFileCollection ();
referenced_assemblies = new List <string> ();
{
if (a == null)
throw new ArgumentNullException ("a");
-
+
referenced_assemblies.Add (a.Location);
}
+ internal void AddCodeCompileUnit (CodeCompileUnit compileUnit)
+ {
+ if (compileUnit == null)
+ throw new ArgumentNullException ("compileUnit");
+ units.Add (compileUnit);
+ }
+
public void AddCodeCompileUnit (BuildProvider buildProvider, CodeCompileUnit compileUnit)
{
if (buildProvider == null)
}
}
}
-
Dictionary <string, string> resources = ResourceFiles;
foreach (KeyValuePair <string, string> de in resources)
options.EmbeddedResources.Add (de.Value);
foreach (string refasm in referenced_assemblies)
options.ReferencedAssemblies.Add (refasm);
- results = provider.CompileAssemblyFromFile (options, files.ToArray ());
-
- // FIXME: generate the code and display it
- if (results.NativeCompilerReturnValue != 0)
- throw new CompilationException (virtualPath, results.Errors, "");
+ results = provider.CompileAssemblyFromFile (options, files.ToArray ());
+ if (results.NativeCompilerReturnValue != 0) {
+ string fileText = null;
+ try {
+ using (StreamReader sr = File.OpenText (results.Errors [0].FileName)) {
+ fileText = sr.ReadToEnd ();
+ }
+ } catch (Exception) {}
+
+ throw new CompilationException (virtualPath, results.Errors, fileText);
+ }
+
Assembly assembly = results.CompiledAssembly;
if (assembly == null) {
if (!File.Exists (options.OutputAssembly)) {
"No assembly returned after compilation!?");
}
- results.CompiledAssembly = Assembly.LoadFrom (options.OutputAssembly);
+ try {
+ results.CompiledAssembly = Assembly.LoadFrom (options.OutputAssembly);
+ } catch (Exception ex) {
+ results.TempFiles.Delete ();
+ throw new HttpException ("Unable to load compiled assembly", ex);
+ }
}
if (!KeepFiles)