动态编译代码:
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地址);
}