将装配体嵌入另一个装配体中 [英] Embed assemblies inside another assembly

查看:76
本文介绍了将装配体嵌入另一个装配体中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我试图将dll嵌入类dll中,作为嵌入式资源而不是引用.换句话说,将另一个程序集封装在我正在编写的程序集中.目标是能够通过我正在编写的方法在嵌入式程序集中使用方法. 到目前为止,我在StackOverFlow或任何论坛上均未取得成功,因此我希望有人能有所作为.这是我到目前为止的摘要.

I'm trying to embed a dll within a class dll as an embedded resource rather than a reference. In another word, encapsulate another assembly within the assembly I'm writing. The goal is to be able to use method in the embedded assembly via the one I'm writing. Thus far, I have no success with StackOverFlow or any forums so I'm hoping someone can shed some light. Here is a snippet of what I have so far. 

使用系统;
   使用System.Runtime.InteropServices;
   使用System.Collections.Generic;
   使用System.Linq;
   使用System.Text;
   使用System.Drawing;
   使用System.IO;
   使用System.IO.Compression;
   使用System.Web;
   使用System.Diagnostics;
   使用System.Reflection;
   使用Aspose.Pdf;
   使用Aspose.Pdf.Facades;
   使用Aspose.Pdf.Text;
   使用Aspose.Pdf.Generator;

using System;
    using System.Runtime.InteropServices;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Drawing;
    using System.IO;
    using System.IO.Compression;
    using System.Web;
    using System.Diagnostics;
    using System.Reflection;
    using Aspose.Pdf;
    using Aspose.Pdf.Facades;
    using Aspose.Pdf.Text;
    using Aspose.Pdf.Generator;

在我的主要方法中:

AppDomain.CurrentDomain.AssemblyResolve + =新的ResolveEventHandler(Resolver);

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(Resolver);

然后:

静态System.Reflection.Assembly解析器(对象发送者,ResolveEventArgs args)
        {
           程序集asposePdf = Assembly.GetExecutingAssembly();
           流_asposePdf = asposePdf.GetManifestResourceStream(string.Format("Aspose.Pdf.dll"));
            byte []程序集=新的byte [_asposePdf.Length];
            _asposePdf.Read(assembly,0,assembly.Length);
           装配a2 = Assembly.Load(装配);
           返回a2;
        }

static System.Reflection.Assembly Resolver(object sender, ResolveEventArgs args)
        {
            Assembly asposePdf = Assembly.GetExecutingAssembly();
            Stream _asposePdf = asposePdf.GetManifestResourceStream(string.Format("Aspose.Pdf.dll"));
            byte[] assembly = new byte[_asposePdf.Length];
            _asposePdf.Read(assembly, 0, assembly.Length);
            Assembly a2 = Assembly.Load(assembly);
            return a2;
        }

* Aspose.Pdf.dll已被设置为项目中的嵌入式资源.

*The Aspose.Pdf.dll had been set as an Embedded Resource within the project.

构建时,我仍然得到:

When build, I still get:

找不到类型或名称空间名称'Aspose'(您是否缺少using指令或程序集引用?)

The type or namespace name 'Aspose' could not be found (are you missing a using directive or an assembly reference?)

任何帮助都将不胜感激.谢谢.

Any help is appreciate. Thanks.

推荐答案

您仍然需要引用程序集来获取要编译的代码.您只需要复制引用的dll即可调试输出. 
You still need to reference the assembly to get code to compile. You just don't need to copy the referenced dll to debug output. 


这篇关于将装配体嵌入另一个装配体中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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