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

编程入门 行业动态 更新时间:2024-10-28 19:27:16
本文介绍了在运行时编译程序集并将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 : "); foreach (CompilerError error in results.Errors ) { errors.AppendFormat("Line {0},{1} : {2} ", 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.

推荐答案

您可以使用 CompilerParameters 的 OutputAssembly 属性来设置输出程序集的名称(路径).从你的例子:

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-08-05 11:26:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1305225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译程序   并将   在一   文件   夹中

发布评论

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

>www.elefans.com

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