2 // Microsoft.CSharp.CSharpCodeProviderTest.cs
5 // Gert Driesen (drieseng@users.sourceforge.net)
12 using System.CodeDom.Compiler;
13 using System.Collections.Specialized;
14 using System.Globalization;
16 using System.Reflection;
17 using Microsoft.CSharp;
18 using NUnit.Framework;
20 namespace MonoTests.Microsoft.CSharp
23 public class CSharpCodeProviderTest
25 private string _tempDir;
26 private CodeDomProvider _codeProvider;
28 private static readonly string _sourceLibrary1 = "public class Test1 {}";
29 private static readonly string _sourceLibrary2 = "public class Test2 {}";
30 private static readonly string _sourceExecutable = "public class Program { static void Main () { } }";
35 _codeProvider = new CSharpCodeProvider ();
36 _tempDir = CreateTempDirectory ();
40 public void TearDown ()
42 RemoveDirectory (_tempDir);
46 public void FileExtension ()
48 Assert.AreEqual ("cs", _codeProvider.FileExtension);
52 public void LanguageOptionsTest ()
54 Assert.AreEqual (LanguageOptions.None, _codeProvider.LanguageOptions);
58 public void GeneratorSupports ()
60 ICodeGenerator codeGenerator = _codeProvider.CreateGenerator ();
61 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEnums), "#1");
62 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ArraysOfArrays), "#2");
63 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.AssemblyAttributes), "#3");
64 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ChainedConstructorArguments), "#4");
65 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ComplexExpressions), "#5");
66 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareDelegates), "#6");
67 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEnums), "#7");
68 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEvents), "#8");
69 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareInterfaces), "#9");
70 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareValueTypes), "#10");
71 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.EntryPointMethod), "#11");
72 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GotoStatements), "#12");
73 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.MultidimensionalArrays), "#13");
74 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.MultipleInterfaceMembers), "#14");
75 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.NestedTypes), "#15");
76 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ParameterAttributes), "#16");
77 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.PublicStaticMembers), "#17");
78 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ReferenceParameters), "#18");
79 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ReturnTypeAttributes), "#19");
80 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.StaticConstructors), "#20");
81 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.TryCatchStatements), "#21");
82 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.Win32Resources), "#22");
84 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareIndexerProperties), "#23");
85 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GenericTypeDeclaration), "#24");
86 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GenericTypeReference), "#25");
87 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.PartialTypes), "#26");
88 Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.Resources), "#27");
93 public void CompileFromFile_InMemory ()
96 string sourceFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
97 using (FileStream f = new FileStream (sourceFile, FileMode.Create)) {
98 using (StreamWriter s = new StreamWriter (f)) {
99 s.Write (_sourceLibrary1);
105 CompilerParameters options = new CompilerParameters ();
106 options.GenerateExecutable = false;
107 options.GenerateInMemory = true;
108 options.TempFiles = new TempFileCollection (_tempDir);
110 options.EmbeddedResources.Add (sourceFile);
113 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
114 CompilerResults results = compiler.CompileAssemblyFromFile (options,
117 // verify compilation was successful
118 AssertCompileResults (results, true);
120 Assembly compiledAssembly = results.CompiledAssembly;
122 Assert.IsNotNull (compiledAssembly, "#1");
123 Assert.AreEqual (string.Empty, compiledAssembly.Location, "#2");
124 Assert.IsNull (results.PathToAssembly, "#3");
125 Assert.IsNotNull (compiledAssembly.GetType ("Test1"), "#4");
127 // verify we don't cleanup files in temp directory too agressively
128 string[] tempFiles = Directory.GetFiles (_tempDir);
129 Assert.AreEqual (1, tempFiles.Length, "#5");
130 Assert.AreEqual (sourceFile, tempFiles[0], "#6");
133 string[] resources = compiledAssembly.GetManifestResourceNames();
134 Assert.IsNotNull (resources, "#7");
135 Assert.AreEqual (1, resources.Length, "#8");
136 Assert.AreEqual ("file.cs", resources[0], "#9");
137 Assert.IsNull (compiledAssembly.GetFile ("file.cs"), "#10");
138 Assert.IsNotNull (compiledAssembly.GetManifestResourceStream ("file.cs"), "#11");
139 ManifestResourceInfo info = compiledAssembly.GetManifestResourceInfo ("file.cs");
140 Assert.IsNotNull (info, "#12");
141 Assert.IsNull (info.FileName, "#13");
142 Assert.IsNull (info.ReferencedAssembly, "#14");
143 Assert.AreEqual ((ResourceLocation.Embedded | ResourceLocation.ContainedInManifestFile), info.ResourceLocation, "#15");
148 public void CompileFromFileBatch_Executable_InMemory ()
150 // create source file
151 string sourceFile1 = Path.Combine (_tempDir, "file1." + _codeProvider.FileExtension);
152 using (FileStream f = new FileStream (sourceFile1, FileMode.Create)) {
153 using (StreamWriter s = new StreamWriter (f)) {
154 s.Write (_sourceLibrary1);
160 string sourceFile2 = Path.Combine (_tempDir, "file2." + _codeProvider.FileExtension);
161 using (FileStream f = new FileStream (sourceFile2, FileMode.Create)) {
162 using (StreamWriter s = new StreamWriter (f)) {
163 s.Write (_sourceExecutable);
169 CompilerParameters options = new CompilerParameters ();
170 options.GenerateExecutable = true;
171 options.GenerateInMemory = true;
172 options.OutputAssembly = string.Empty;
173 options.TempFiles = new TempFileCollection (_tempDir);
175 options.EmbeddedResources.Add (sourceFile1);
176 options.LinkedResources.Add (sourceFile2);
179 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
180 CompilerResults results = compiler.CompileAssemblyFromFileBatch (options,
181 new string [] { sourceFile1, sourceFile2 });
183 // verify compilation was successful
184 AssertCompileResults (results, true);
186 Assembly compiledAssembly = results.CompiledAssembly;
188 Assert.IsNotNull (compiledAssembly, "#A1");
189 Assert.AreEqual (string.Empty, compiledAssembly.Location, "#A2");
190 Assert.IsNull (results.PathToAssembly, "#A3");
191 Assert.IsNotNull (options.OutputAssembly, "#A4");
192 Assert.AreEqual (".exe", Path.GetExtension (options.OutputAssembly), "#A5");
193 Assert.AreEqual (_tempDir, Path.GetDirectoryName (options.OutputAssembly), "#A6");
194 Assert.IsFalse (File.Exists (options.OutputAssembly), "#A7");
196 Assert.IsNotNull (compiledAssembly.GetType ("Test1"), "#B1");
197 Assert.IsNotNull (compiledAssembly.GetType ("Program"), "#B2");
199 // verify we don't cleanup files in temp directory too agressively
200 string [] tempFiles = Directory.GetFiles (_tempDir);
201 Assert.AreEqual (2, tempFiles.Length, "#C1");
202 Assert.IsTrue (File.Exists (sourceFile1), "#C2");
203 Assert.IsTrue (File.Exists (sourceFile2), "#C3");
206 string[] resources = compiledAssembly.GetManifestResourceNames();
207 Assert.IsNotNull (resources, "#D1");
208 Assert.AreEqual (2, resources.Length, "#D2");
210 Assert.IsTrue (resources[0] == "file1.cs" || resources [0] == "file2.cs", "#E1");
211 Assert.IsNull (compiledAssembly.GetFile ("file1.cs"), "#E2");
212 Assert.IsNotNull (compiledAssembly.GetManifestResourceStream ("file1.cs"), "#E3");
213 ManifestResourceInfo info = compiledAssembly.GetManifestResourceInfo ("file1.cs");
214 Assert.IsNotNull (info, "#E4");
215 Assert.IsNull (info.FileName, "#E5");
216 Assert.IsNull (info.ReferencedAssembly, "#E6");
217 Assert.AreEqual ((ResourceLocation.Embedded | ResourceLocation.ContainedInManifestFile), info.ResourceLocation, "#E7");
219 Assert.IsTrue (resources[1] == "file1.cs" || resources [1] == "file2.cs", "#F1");
221 compiledAssembly.GetFile ("file2.cs");
223 } catch (FileNotFoundException) {
226 compiledAssembly.GetManifestResourceStream ("file2.cs");
228 } catch (FileNotFoundException) {
230 info = compiledAssembly.GetManifestResourceInfo ("file2.cs");
231 Assert.IsNotNull (info, "#F4");
232 Assert.IsNotNull (info.FileName, "#F5");
233 Assert.AreEqual ("file2.cs", info.FileName, "#F6");
234 Assert.IsNull (info.ReferencedAssembly, "#F7");
235 Assert.AreEqual ((ResourceLocation) 0, info.ResourceLocation, "#F8");
240 public void CompileFromFileBatch_Library_InMemory ()
242 // create source file
243 string sourceFile1 = Path.Combine (_tempDir, "file1." + _codeProvider.FileExtension);
244 using (FileStream f = new FileStream (sourceFile1, FileMode.Create)) {
245 using (StreamWriter s = new StreamWriter (f)) {
246 s.Write (_sourceLibrary1);
252 string sourceFile2 = Path.Combine (_tempDir, "file2." + _codeProvider.FileExtension);
253 using (FileStream f = new FileStream (sourceFile2, FileMode.Create)) {
254 using (StreamWriter s = new StreamWriter (f)) {
255 s.Write (_sourceLibrary2);
261 CompilerParameters options = new CompilerParameters ();
262 options.GenerateExecutable = false;
263 options.GenerateInMemory = true;
264 options.TempFiles = new TempFileCollection (_tempDir);
266 options.EmbeddedResources.Add (sourceFile1);
267 options.LinkedResources.Add (sourceFile2);
270 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
271 CompilerResults results = compiler.CompileAssemblyFromFileBatch (options,
272 new string [] { sourceFile1, sourceFile2 });
274 // verify compilation was successful
275 AssertCompileResults (results, true);
277 Assembly compiledAssembly = results.CompiledAssembly;
279 Assert.IsNotNull (compiledAssembly, "#A1");
280 Assert.AreEqual (string.Empty, compiledAssembly.Location, "#A2");
281 Assert.IsNull (results.PathToAssembly, "#A3");
282 Assert.IsNotNull (options.OutputAssembly, "#A4");
283 Assert.AreEqual (".dll", Path.GetExtension (options.OutputAssembly), "#A5");
284 Assert.AreEqual (_tempDir, Path.GetDirectoryName (options.OutputAssembly), "#A6");
285 Assert.IsFalse (File.Exists (options.OutputAssembly), "#A7");
287 Assert.IsNotNull (compiledAssembly.GetType ("Test1"), "#B1");
288 Assert.IsNotNull (compiledAssembly.GetType ("Test2"), "#B2");
290 // verify we don't cleanup files in temp directory too agressively
291 string [] tempFiles = Directory.GetFiles (_tempDir);
292 Assert.AreEqual (2, tempFiles.Length, "#C1");
293 Assert.IsTrue (File.Exists (sourceFile1), "#C2");
294 Assert.IsTrue (File.Exists (sourceFile2), "#C3");
297 string[] resources = compiledAssembly.GetManifestResourceNames();
298 Assert.IsNotNull (resources, "#D1");
299 Assert.AreEqual (2, resources.Length, "#D2");
301 Assert.IsTrue (resources[0] == "file1.cs" || resources [0] == "file2.cs", "#E1");
302 Assert.IsNull (compiledAssembly.GetFile ("file1.cs"), "#E2");
303 Assert.IsNotNull (compiledAssembly.GetManifestResourceStream ("file1.cs"), "#E3");
304 ManifestResourceInfo info = compiledAssembly.GetManifestResourceInfo ("file1.cs");
305 Assert.IsNotNull (info, "#E4");
306 Assert.IsNull (info.FileName, "#E5");
307 Assert.IsNull (info.ReferencedAssembly, "#E6");
308 Assert.AreEqual ((ResourceLocation.Embedded | ResourceLocation.ContainedInManifestFile), info.ResourceLocation, "#E7");
310 Assert.IsTrue (resources[1] == "file1.cs" || resources [1] == "file2.cs", "#F1");
312 compiledAssembly.GetFile ("file2.cs");
314 } catch (FileNotFoundException) {
317 compiledAssembly.GetManifestResourceStream ("file2.cs");
319 } catch (FileNotFoundException) {
321 info = compiledAssembly.GetManifestResourceInfo ("file2.cs");
322 Assert.IsNotNull (info, "#F4");
323 Assert.IsNotNull (info.FileName, "#F5");
324 Assert.AreEqual ("file2.cs", info.FileName, "#F6");
325 Assert.IsNull (info.ReferencedAssembly, "#F7");
326 Assert.AreEqual ((ResourceLocation) 0, info.ResourceLocation, "#F8");
331 public void CompileFromSource_InMemory ()
333 // create a file in temp directory to ensure that compiler is not removing
334 // too much (temporary) files
335 string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
336 using (FileStream fs = File.Create (tempFile)) {
340 CompilerParameters options = new CompilerParameters ();
341 options.GenerateExecutable = false;
342 options.GenerateInMemory = true;
343 options.TempFiles = new TempFileCollection (_tempDir);
345 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
346 CompilerResults results = compiler.CompileAssemblyFromSource (options,
349 // verify compilation was successful
350 AssertCompileResults (results, true);
352 Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
353 Assert.IsNull (results.PathToAssembly, "#2");
354 Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
356 // verify we don't cleanup files in temp directory too agressively
357 string[] tempFiles = Directory.GetFiles (_tempDir);
358 Assert.AreEqual (1, tempFiles.Length, "#4");
359 Assert.AreEqual (tempFile, tempFiles[0], "#5");
363 public void CompileFromSourceBatch_InMemory ()
365 // create a file in temp directory to ensure that compiler is not removing
366 // too much (temporary) files
367 string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
368 using (FileStream fs = File.Create (tempFile)) {
372 string outputAssembly = Path.Combine (_tempDir, "sourcebatch.dll");
374 CompilerParameters options = new CompilerParameters ();
375 options.GenerateExecutable = false;
376 options.GenerateInMemory = true;
377 options.OutputAssembly = outputAssembly;
378 options.TempFiles = new TempFileCollection (_tempDir);
380 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
381 CompilerResults results = compiler.CompileAssemblyFromSourceBatch (options,
382 new string [] { _sourceLibrary1, _sourceLibrary2 });
384 // verify compilation was successful
385 AssertCompileResults (results, true);
387 Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#A1");
388 Assert.IsNull (results.PathToAssembly, "#A2");
389 Assert.IsNotNull (options.OutputAssembly, "#A3");
390 Assert.AreEqual (outputAssembly, options.OutputAssembly, "#A4");
391 Assert.IsTrue (File.Exists (outputAssembly), "#A5");
393 Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#B1");
394 Assert.IsNotNull (results.CompiledAssembly.GetType ("Test2"), "#B2");
396 // verify we don't cleanup files in temp directory too agressively
397 string[] tempFiles = Directory.GetFiles (_tempDir);
398 Assert.AreEqual (2, tempFiles.Length, "#C1");
399 Assert.AreEqual (tempFile, tempFiles[0], "#C2");
400 Assert.AreEqual (outputAssembly, tempFiles [1], "#C3");
404 public void CompileFromDom_NotInMemory ()
406 // create a file in temp directory to ensure that compiler is not removing
407 // too much (temporary) files
408 string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
409 using (FileStream fs = File.Create (tempFile)) {
413 // compile and verify result in separate appdomain to avoid file locks
414 AppDomain testDomain = CreateTestDomain ();
415 CrossDomainTester compileTester = CreateCrossDomainTester (testDomain);
417 string outputAssembly = null;
420 outputAssembly = compileTester.CompileAssemblyFromDom (_tempDir);
422 AppDomain.Unload (testDomain);
425 // there should be two files in temp dir: temp file and output assembly
426 string[] tempFiles = Directory.GetFiles (_tempDir);
427 Assert.AreEqual (2, tempFiles.Length, "#1");
428 Assert.IsTrue (File.Exists (outputAssembly), "#2");
429 Assert.IsTrue (File.Exists (tempFile), "#3");
433 public void CompileFromDomBatch_NotInMemory ()
435 // create a file in temp directory to ensure that compiler is not removing
436 // too much (temporary) files
437 string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
438 using (FileStream fs = File.Create (tempFile)) {
442 // compile and verify result in separate appdomain to avoid file locks
443 AppDomain testDomain = CreateTestDomain ();
444 CrossDomainTester compileTester = CreateCrossDomainTester (testDomain);
446 string outputAssembly = null;
448 outputAssembly = compileTester.CompileAssemblyFromDomBatch (_tempDir);
450 AppDomain.Unload (testDomain);
453 // there should be two files in temp dir: temp file and output assembly
454 string[] tempFiles = Directory.GetFiles (_tempDir);
455 Assert.AreEqual (2, tempFiles.Length, "#1");
456 Assert.IsTrue (File.Exists (outputAssembly), "#2");
457 Assert.IsTrue (File.Exists (tempFile), "#3");
461 public void CompileFromDom_InMemory ()
463 // create a file in temp directory to ensure that compiler is not removing
464 // too much (temporary) files
465 string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
466 using (FileStream fs = File.Create (tempFile)) {
470 CompilerParameters options = new CompilerParameters ();
471 options.GenerateExecutable = false;
472 options.GenerateInMemory = true;
473 options.TempFiles = new TempFileCollection (_tempDir);
475 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
476 CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());
478 // verify compilation was successful
479 AssertCompileResults (results, true);
481 Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
482 Assert.IsNull (results.PathToAssembly, "#2");
484 // verify we don't cleanup files in temp directory too agressively
485 string[] tempFiles = Directory.GetFiles (_tempDir);
486 Assert.AreEqual (1, tempFiles.Length, "#3");
487 Assert.AreEqual (tempFile, tempFiles[0], "#4");
491 public void CompileFromDomBatch_InMemory ()
493 // create a file in temp directory to ensure that compiler is not removing
494 // too much (temporary) files
495 string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
496 using (FileStream fs = File.Create (tempFile)) {
500 CompilerParameters options = new CompilerParameters ();
501 options.GenerateExecutable = false;
502 options.GenerateInMemory = true;
503 options.TempFiles = new TempFileCollection (_tempDir);
505 ICodeCompiler compiler = _codeProvider.CreateCompiler ();
506 CompilerResults results = compiler.CompileAssemblyFromDomBatch (options,
507 new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });
509 // verify compilation was successful
510 AssertCompileResults (results, true);
512 Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
513 Assert.IsNull (results.PathToAssembly, "#2");
515 // verify we don't cleanup files in temp directory too agressively
516 string[] tempFiles = Directory.GetFiles (_tempDir);
517 Assert.AreEqual (1, tempFiles.Length, "#3");
518 Assert.AreEqual (tempFile, tempFiles[0], "#4");
521 private static string CreateTempDirectory ()
523 // create a uniquely named zero-byte file
524 string tempFile = Path.GetTempFileName ();
525 // remove the temporary file
526 File.Delete (tempFile);
527 // create a directory named after the unique temporary file
528 Directory.CreateDirectory (tempFile);
529 // return the path to the temporary directory
533 private static void RemoveDirectory (string path)
536 if (Directory.Exists (path)) {
537 string[] directoryNames = Directory.GetDirectories (path);
538 foreach (string directoryName in directoryNames) {
539 RemoveDirectory (directoryName);
541 string[] fileNames = Directory.GetFiles (path);
542 foreach (string fileName in fileNames) {
543 File.Delete (fileName);
545 Directory.Delete (path, true);
547 } catch (Exception ex) {
548 throw new AssertionException ("Unable to cleanup '" + path + "'.", ex);
552 private static void AssertCompileResults (CompilerResults results, bool allowWarnings)
554 foreach (CompilerError compilerError in results.Errors) {
555 if (allowWarnings && compilerError.IsWarning) {
559 throw new Exception (compilerError.ToString ());
563 private static AppDomain CreateTestDomain ()
565 return AppDomain.CreateDomain ("CompileFromDom", AppDomain.CurrentDomain.Evidence,
566 AppDomain.CurrentDomain.SetupInformation);
569 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
571 Type testerType = typeof (CrossDomainTester);
573 return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
574 testerType.Assembly.FullName, testerType.FullName, false,
575 BindingFlags.Public | BindingFlags.Instance, null, new object[0],
576 CultureInfo.InvariantCulture, new object[0], domain.Evidence);
579 // do not use the Assert class as this will introduce failures if the
580 // nunit.framework assembly is not in the GAC
581 private class CrossDomainTester : MarshalByRefObject
583 public string CompileAssemblyFromDom (string tempDir)
585 CompilerParameters options = new CompilerParameters ();
586 options.GenerateExecutable = false;
587 options.GenerateInMemory = false;
588 options.TempFiles = new TempFileCollection (tempDir);
590 CSharpCodeProvider codeProvider = new CSharpCodeProvider ();
591 ICodeCompiler compiler = codeProvider.CreateCompiler ();
592 CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());
594 // verify compilation was successful
595 AssertCompileResults (results, true);
597 if (results.CompiledAssembly.Location.Length == 0)
598 throw new Exception ("Location should not be empty string");
599 if (results.PathToAssembly == null)
600 throw new Exception ("PathToAssembly should not be null");
602 return results.PathToAssembly;
605 public string CompileAssemblyFromDomBatch (string tempDir)
607 CompilerParameters options = new CompilerParameters ();
608 options.GenerateExecutable = false;
609 options.GenerateInMemory = false;
610 options.TempFiles = new TempFileCollection (tempDir);
612 CSharpCodeProvider codeProvider = new CSharpCodeProvider ();
613 ICodeCompiler compiler = codeProvider.CreateCompiler ();
614 CompilerResults results = compiler.CompileAssemblyFromDomBatch (options, new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });
616 // verify compilation was successful
617 AssertCompileResults (results, true);
619 if (results.CompiledAssembly.Location.Length == 0)
620 throw new Exception ("Location should not be empty string");
621 if (results.PathToAssembly == null)
622 throw new Exception ("PathToAssembly should not be null");
624 return results.PathToAssembly;