110,534
社区成员
发帖
与我相关
我的任务
分享
void BtnStartClick(object sender, System.EventArgs e)
{
string Str1 = txtFileUrl.Text; //这里是给出具体的a.cs文件
System.Diagnostics.Process
proc = new System.Diagnostics.Process();
proc.EnableRaisingEvents = false;
proc.StartInfo.FileName = "csc " + Str1; //调用线程编译
proc.Start();
this.Close();
}
using System.CodeDom.Compiler;
using System.Reflection;
CodeDomProvider cdp = CodeDomProvider.CreateProvider("C#");
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = true;//生成可执行文件
cp.OutputAssembly = @"d:\a.exe";//文件名
//如果仅生成文件,不用以下代码,如果要反射调用,请用以下动态生成的程序集
CompilerResults cr = cdp.CompileAssemblyFromFile(cp, "fileName");//从文件编译
//cdp.CompileAssemblyFromSource(cp, "source");//从字符串编译
Assembly ass = cr.CompiledAssembly;
//更具体的,请参考 CodeDom 的相关主题