سلام این رو قبلا درست کرده بود ولی تحت کنسول میشه و تحت وین فرم رو نمیدونم شاید بدردتون بخوره برای اینکه که کار کنه دو تا تکست باکس و دو باتن قرار بدید و تو یکی از باتن ها کد زیر رو بنویسید البته دقت کنید که باید using ,System.CodeDomSystem.CodeDom.Compiler رو هم انجام بدبد به صورت زیر
using System.CodeDom;
using System.CodeDom.Compiler;
CSCodeProvider codeProvider = new CSCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
string Output = "c:\\Out.exe";
Button ButtonObject = (Button)sender;
TextBox2.Text = "";
CompilerParameters parameters = new CompilerParameters();
CompilerResults results = default(CompilerResults);
parameters.GenerateExecutable = true;
parameters.OutputAssembly = Output;
results = icc.CompileAssemblyFromSource(parameters, TextBox1.Text);
if (results.Errors.Count > 0) {
TextBox2.ForeColor = Color.Red;
CompilerError CompErr = default(CompilerError);
foreach ( CompErr in results.Errors) {
TextBox2.Text = TextBox2.Text + "Line number " + CompErr.Line + ", Error Number: " + CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";" + Environment.NewLine + Environment.NewLine;
}
} else {
TextBox2.ForeColor = Color.Blue;
TextBox2.Text = "Success!";
if (ButtonObject.Text == "Run")
Process.Start(Output);
}