当前位置:编程学习 > C#/ASP.NET >>

如何 动态编译自己写的代码

答案:CSharpCodeProvider _coder=new CSharpCodeProvider();
ICodeCompiler complier=_coder.CreateCompiler();
CompilerParameters _par=new CompilerParameters();
_par.GenerateExecutable=true;

_par.OutputAssembly="sy1.exe";//设置应用程序名
_par.MainClass="sy1";//设置主类

_par.IncludeDebugInformation=true;

foreach(Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
{
_par.ReferencedAssemblies.Add(asm.Location);
}

string get_Code=_code;

CompilerResults _res=complier.CompileAssemblyFromSource(_par,get_Code);

if(_res.Errors.Count>0)
{
ErrInfo pEi=new ErrInfo();
pEi.Show();
ListBox getList=pEi.getList;
foreach(CompilerError err in _res.Errors)
{

getList.Items.Add(err.ErrorText);
}
}
else
{
MessageBox.Show("success");
}

上一个:在团队开发环境中使用 Visual Studio .NET (二)
下一个:在.net中如何把调用存储过程代码写入数据连接层中

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,