Could someone help me do this, im just trying to make my app compile an exe from a string in the source code, here's what I'm doing:
csharp
protected string do_compile(string[] code, string outputFile, bool isexe)
{
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters parameters;
// These are the equivalent of the references part of a visual studio project
string[] refrences = { "System", "System.Data", "System.Windows.Forms" };
// Create params for compile
parameters = new CompilerParameters(refrences, outputFile, true);
parameters.GenerateExecutable = isexe;
// Send it all to the compiler
CompilerResults results = provider.CompileAssemblyFromSource(parameters, code);
String result;
// Check for errors
if (results.Errors.Count > 0)
{ // We had an error
result = "Error";
// Add the erorrs to the result
foreach (CompilerError ce in results.Errors)
{
result += "\n" + ce.ToString();
MessageBox.Show(result);
}
}
else
{ // All was fine
result = "Success";
MessageBox.Show(result);
}
return result;
}
private void button1_Click(object sender, EventArgs e)
{
string[] code = { "MessageBox.Show('Hi');" };
string output = @"E:\test.exe";
do_compile(code, output, true);
}
however I get errors (the program complies fine but once I click the button) saying "Metadata file System could not be found, Metadata file System.Data could not be found, Metadata file System.Windows.Forms could not be found" Anyone have an idea on how to make it work? Thanks