您的位置:首页 > 编程语言

动态编译代码,生成dll

2010-04-28 13:06 477 查看
动态编译代码:

string CsPath(string filename)

{

string path=Application.StartPath+"Test";
string file=path+filename;
return file;
}

void WriteContent()

{

try
{
StreamWriter sw=new StreamWriter(cs,false);
sw.Write();
sw.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}

CompilerResult crrr()

{

string[] paras={"System.dll","....其他dll"};
CompilerParameters cp=new CompilerParameters (paras);
CodeDomProvider cdp=new Microsoft.CSharp(other).CSharpCodeDomProvider();
CompilerResult cr=cp.CompileAssemblyFromFile(参数--cp,要编译文件地址----CsPath());
return cr;
}

生成dll:

void CreateDll()

{

CSharpCodeProvider csp=new Microsoft.CSharp.CSharpCodeProvider();
CompilerParameters cp=new CompilerParameters(new string[]{"System.dll"});
cp.GenerateMemory=true;
cp.OutputAssembly="dll生成地址";
CompilerResult cr=csp.CompilerAssemblyFromFile(cp,dll地址);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐