Hack Forums
[C#] [Source]CodeDom for C# - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] [Source]CodeDom for C# (/showthread.php?tid=819941)



[Source]CodeDom for C# - Mr. Anderson - Nov 14, 2010

Not sure if this has been posted(I searched and the only result I got was a $harecash link).
All Credit the Prototype or whoever made the visual Basic one.

You must Reference the Microsoft.CSharp dll and Microsoft.VisualBasic in order to use this.
I removed the error displaying because it was causing errors :p

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.CodeDom.Compiler;
using Microsoft.VisualBasic;

namespace WindowsFormsApplication1
{
    class icompilecs
    {
  public static void GenerateExecutable(string Output, string Source, string Icon)
  {

    ICodeCompiler Compiler = (new Microsoft.CSharp.CSharpCodeProvider()).CreateCompiler();
    CompilerParameters Parameters = new CompilerParameters();
    CompilerResults cResults = default(CompilerResults);

    Parameters.GenerateExecutable = true;
    Parameters.OutputAssembly = Output;
    Parameters.ReferencedAssemblies.Add("System.dll");
    Parameters.ReferencedAssemblies.Add("System.Data.dll");
    Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");

    dynamic Version = new Dictionary<string, string>();
    Version.Add("CompilerVersion", "v2.0");

    string ICO = System.IO.Path.GetTempPath() + "\\iCompiler.ico";

    if (!string.IsNullOrEmpty(Icon))
    {
    System.IO.File.Copy(Icon, ICO);
    Parameters.CompilerOptions += " /win32icon:" + ICO;
    }

    cResults = Compiler.CompileAssemblyFromSource(Parameters, Source);

    if (cResults.Errors.Count > 0)
    {
    foreach (object CompilerError_loopVariable in cResults.Errors)
    {

    }

    }
    else if (cResults.Errors.Count == 0)
    {
    }
    if (!string.IsNullOrEmpty(Icon))
    {
    System.IO.File.Delete(ICO);
    }
  }

    }
}

Happy Leeching!👍


* - xhtmlphp™ - Nov 14, 2010

Why is there empty loops/else statements?


* - Mr. Anderson - Nov 14, 2010

because the error code displayer caused it have errors. I am actually fixing this now.