本文介绍了在运行时编译程序集并将dll保存在文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
Microsoft.CSharp.CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); CompilerParameters compilerparams = new CompilerParameters(); compilerparams.GenerateInMemory = false; CompilerResults results = compiler.CompileAssemblyFromSource(compilerparams, code); if (results.Errors.HasErrors) { StringBuilder errors = new StringBuilder("Compiler Errors :\r\n"); foreach (CompilerError error in results.Errors ) { errors.AppendFormat("Line {0},{1}\t: {2}\n", error.Line, error.Column, error.ErrorText); } throw new Exception(errors.ToString()); } else { return results.CompiledAssembly; }如何将创建的dll保存到我自己的特定文件夹?当我调试时,不知何故装配位置在'AppData / Local / Temp /'文件夹。
How do I save the created dll to my own specific folder? When I debug, somehow the assembly location is at 'AppData/Local/Temp/' folder.
推荐答案code> OutputAssembly 属性 CompilerParameters 设置输出程序集的名称(路径)。 从您的示例:
You could use the OutputAssembly property of CompilerParameters to sets the name (path) of the output assembly. From your example:
... CompilerParameters compilerparams = new CompilerParameters(); compilerparams.GenerateInMemory = false; compilerparams.OutputAssembly = "OutputAssembly.dll"; CompilerResults results = compiler.CompileAssemblyFromSource(compilerparams, code); ...更多推荐
在运行时编译程序集并将dll保存在文件夹中
发布评论