/// <summary> /// 动态编译并执行代码 /// </summary> /// <param name="code">代码</param> /// <param name="newPath">输出dll的路径</param> /// <returns>返回输出内容</returns> private CompilerResults debugRun(string[] code, string newPath) { CSharpCodeProvider complier = new CSharpCodeProvider(); //设置编译参数 CompilerParameters paras = new CompilerParameters(); //引入第三方dll paras.ReferencedAssemblies.Add(@"System.dll"); paras.ReferencedAssemblies.Add(@"System.configuration.dll"); paras.ReferencedAssemblies.Add(@"System.Data.dll"); paras.ReferencedAssemblies.Add(@"System.Management.dll"); paras.ReferencedAssemblies.Add(@"System.Web.dll"); paras.ReferencedAssemblies.Add(@"System.Xml.dll"); paras.ReferencedAssemblies.Add(@"F:AuthorizationServiceLibNewtonsoft.JsonNet20Newtonsoft.Json.dll"); //引入自定义dll //paras.ReferencedAssemblies.Add(@"D:自定义方法自定义方法inLogHelper.dll"); //是否内存中生成输出 paras.GenerateInMemory = false; //是否生成可执行文件 paras.GenerateExecutable = false; paras.OutputAssembly = newPath; //编译代码 CompilerResults result = complier.CompileAssemblyFromSource(paras, code); return result; }