在运行时编译程序集并将dll保存在文件夹中

编程入门 行业动态 更新时间:2024-10-28 05:23:38
本文介绍了在运行时编译程序集并将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保存在文件夹中

本文发布于:2023-11-13 09:14:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583978.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译程序   并将   文件   夹中   dll

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!