日期:2014-05-17  浏览次数:20932 次

[动态编译]如何在动态编译生成的动态库中添加图片资源及使用?
public static void abc()
        {
            #region 要执行的代码

            string strCode = @" 
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
namespace aaa
{
    public class bbb
    {
        public static string ccc(string name)
        {
            return ""abc"";
        }
    }
}";
            #endregion
            #region 编译参数
            CompilerParameters objCompilerParams = new CompilerParameters();

            objCompilerParams.GenerateExecutable = false;   //编译成exe还是dll
            objCompilerParams.GenerateInMemory = false;           //是否写入内存,不写入内存就写入磁盘
            objCompilerParams.OutputAssembly = "E:\\abc.dll";         //输出路径
            objCompilerParams.IncludeDebugInformation = false; //是否产生pdb调试文件      默认是false
            objCompilerParams.ReferencedAssemblies.Add("System.dll");
            objCompilerParams.ReferencedAssemblies.Add("System.Core.dll");

            //编译器选项:编译成(存储在内存中)的DLL
            /*objCompilerParams.CompilerOptions = "/target:library /optimize";
            //编译时在内存输出 
            objCompilerParams.GenerateInMemory = true;
            //不生成调试信息 
            objCompilerParams.IncludeDebugInformation = false;*/
            #endregion
            #region 编译
            //创建编译类
            CSharpCodeProvider objCompiler = new CSharpCodeProvider();
            //进行编译
            CompilerResults objCompileResults = objCompiler.CompileAssemblyFromSource(objCompilerParams, strCode);
            #endregion
            #regi