title: Creating winforms executable dynamically C#
body: <p>I want to create an application, that will take out the text from textBox1, compile it, and save it as an executable. I never tried this before, but I would really like to get it working. <strong>This is the code that I'm using in my "compiler" application:</strong></p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  using System.CodeDom.Compiler;
  using Microsoft.CSharp;
  using System.Diagnostics;
  
  namespace Compiler
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              CSharpCodeProvider codeProvider = new CSharpCodeProvider();
              ICodeCompiler icc = codeProvider.CreateCompiler();
              string Output = "out.exe";
              Button ButtonObject = (Button)sender;
              CompilerParameters parameters = new CompilerParameters();
              string[] references = { "System.dll","System.Windows.Forms.dll","System.Drawing.dll" };
  
              parameters.EmbeddedResources.AddRange(references);
              parameters.GenerateExecutable = true;
              parameters.OutputAssembly = Output;
              CompilerResults results = icc.CompileAssemblyFromSource(parameters, textBox1.Text);
  
              if (results.Errors.Count &gt; 0)
              {
                  foreach (CompilerError CompErr in results.Errors)
                  {
                      MessageBox.Show(CompErr.ToString());
                  }
              }
              else
              {
                  //Successful Compile
                  textBox1.ForeColor = Color.Blue;
                  textBox1.Text = "Success!";
              }
  
          }
      }
  }
  </code></pre>
  
  <p><strong>The textbox1 text, meaning the source that I am trying to compile is:</strong></p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
  System.Windows.Forms.Form f = new System.Windows.Forms.Form(); 
  f.ShowDialog();
      }
  }
  </code></pre>
  
  <p>Basically, I am trying to generate an executable file dynamically, that will just show a Form. I've also tried, instead of making and showing a form to show a System.Windows.MessageBox.Show("testing");</p>
  
  <p>In both cases I get this errors:</p>
  
  <blockquote>
    <p>Line number 5, Error Number: CS0234, 'The type or namespace name
    'Windows' does not exist in the namespace 'System' (are you missing an
    assembly reference?);</p>
    
    <p>Line number 5, Error Number: CS0234, 'The type or namespace name
    'Windows' does not exist in the namespace 'System' (are you missing an
    assembly reference?);</p>
  </blockquote>