動態編譯代碼,生成dll

動態編譯代碼:

 

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地址);

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章