iTz_Mercury

C# Codedom Class [modified]

May 17th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.CodeDom;
  5. using System.CodeDom.Compiler;
  6. using System.Windows.Forms;
  7.  
  8. namespace CodomCompiler
  9. {
  10.  
  11.     class CodeDom
  12.     {
  13.         public static bool Compile(string EXE_Name, string Source)
  14.         {
  15.             CodeDomProvider Compiler = CodeDomProvider.CreateProvider("CSharp");
  16.             CompilerParameters Parameters = new CompilerParameters();
  17.             CompilerResults cResults = default(CompilerResults);
  18.  
  19.             Parameters.GenerateExecutable = true;
  20.             Parameters.OutputAssembly = EXE_Name;
  21.             Parameters.ReferencedAssemblies.Add("System.dll");
  22.             Parameters.CompilerOptions = " /target:winexe";
  23.             Parameters.TreatWarningsAsErrors = false;
  24.             cResults = Compiler.CompileAssemblyFromSource(Parameters, Source);
  25.  
  26.             if (cResults.Errors.Count > 0)
  27.             {
  28.                 foreach (CompilerError CompilerError_loopVariable in cResults.Errors)
  29.                 {
  30.                     CompilerError error = CompilerError_loopVariable;
  31.                     MessageBox.Show("Error: " + error.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
  32.                 }
  33.                 return false;
  34.             }
  35.             else if (cResults.Errors.Count == 0)
  36.             {
  37.                 MessageBox.Show("Compiled Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  38.                 return true;
  39.             }
  40.             MessageBox.Show("Compiled Successfully!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  41.             return true;
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment