动态生成的DLL组件在运行时 [英] Generating DLL assembly dynamically at run time

查看:288
本文介绍了动态生成的DLL组件在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我有一个正在动态生成的一些code。换言之,一个C#cs文件是由程序动态地创建,并且意图是包括在另一个项目这C#文件

目前的挑战是,我想生成一个.DLL文件,而不是生成一个C#cs文件,以便它可以通过任何类型的.NET应用程序(不仅是C#),因此更加有用引用。

解决方案

 使用系统codeDom.Compiler。
使用System.Diagnostics程序;
使用Microsoft.CSharp;

CSHARP codeProvider codeProvider =新CSHARP codeProvider();
I codeCompiler ICC = codeProvider.CreateCompiler();
。系统codeDom.Compiler.CompilerParameters参数=新CompilerParameters();
parameters.GenerateExecutable = FALSE;
parameters.OutputAssembly =AutoGen.dll;
CompilerResults结果= icc.CompileAssemblyFromSource(参数,你的codeAsString);
 

http://support.microsoft.com/kb/304655

改编

Currently I have some code that is being generated dynamically. In other words, a C# .cs file is created dynamically by the program, and the intention is to include this C# file in another project.

The challenge is that I would like to generate a .DLL file instead of generating a C# .cs file so that it could be referenced by any kind of .NET application (not only C#) and therefore be more useful.

解决方案

using System.CodeDom.Compiler;
using System.Diagnostics;
using Microsoft.CSharp;

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler icc = codeProvider.CreateCompiler();
System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
parameters.GenerateExecutable = false;
parameters.OutputAssembly = "AutoGen.dll";
CompilerResults results = icc.CompileAssemblyFromSource(parameters, yourCodeAsString);

Adapted from http://support.microsoft.com/kb/304655

这篇关于动态生成的DLL组件在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆