使用AssemblyBuilder,我怎样才能使所有被引用的组件嵌入而不是在保存的组件链接或任何? [英] Using AssemblyBuilder, how can I make all or any of the referenced assemblies embedded instead of linked in the saved assembly?

查看:211
本文介绍了使用AssemblyBuilder,我怎样才能使所有被引用的组件嵌入而不是在保存的组件链接或任何?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个执行的程序集,它产生另一个组件动态使用AssemblyBuilder。

I have an executing assembly, which generates another assembly dynamically using AssemblyBuilder.

生成组件由职能,只是在执行的程序集测试某些类别的建设。由于在执行程序集生成的程序集引用类的功能,我想有执行大会在其创建的组件中嵌入本身。

The generated assembly consists of functions which simply test the construction of certain classes in the executing assembly. Since the functions in the generated assembly reference classes in the executing assembly, I want to have the executing assembly embed itself in the assembly it creates.

到目前为止,我只设法生成链接到执行程序集的程序集,但没有一个嵌入它。重要的是,我还有最后一个组件(.dll文件)。

So far, I've only managed to generate an assembly that links to the executing assembly, but not one that embeds it. It's important that I have just one final assembly (.dll).

我需要的组件嵌入作为一种资源?如果是这样,怎么样?我不希望有写code动态加载内嵌汇编,除非这是唯一的办法。我在找东西容易像AssemblyBuilder.EmbedAssembly(GetExecutingAssembly())。

Do I need to embed the assembly as a resource? If so, how? I don't want to have to write code to load the embedded assembly dynamically, unless that's the only way. I'm looking for something easy like AssemblyBuilder.EmbedAssembly( GetExecutingAssembly() ).

推荐答案

有没有简单的方法。至少有两种选择:

There's no easy way. You have at least two choices:

  • 嵌入引用的程序集的<一个href="http://msdn.microsoft.com/en-us/library/system.reflection.emit.modulebuilder.definemanifestresource.aspx"相对=nofollow>管理资源,并散发出的组装吊钩加载组件从资源流的需求。
  • 使用 ILMerge 合并使用后散发出的步骤装配在一起。
  • Embed the referenced assemblies as managed resources, and emit an assembly load hook that will load the assemblies from the resource stream on demand.
  • Use a post emit step using ILMerge to merge the assemblies all together.

这篇关于使用AssemblyBuilder,我怎样才能使所有被引用的组件嵌入而不是在保存的组件链接或任何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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