使用AssemblyBuilder,如何将所有或任何引用的程序集嵌入而不是链接到保存的程序集中?

发布于 2024-07-19 18:11:18 字数 365 浏览 4 评论 0原文

我有一个执行程序集,它使用 AssemblyBuilder 动态生成另一个程序集。

生成的程序集由一些函数组成,这些函数只是测试执行程序集中某些类的构造。 由于生成的程序集中的函数引用执行程序集中的类,因此我希望执行程序集将自身嵌入到它创建的程序集中。

到目前为止,我只生成了一个链接到执行程序集的程序集,但没有生成嵌入它的程序集。 重要的是我只有一个最终程序集 (.dll)。

我需要将程序集作为资源嵌入吗? 如果是这样,怎么办? 我不想编写代码来动态加载嵌入式程序集,除非这是唯一的方法。 我正在寻找像 AssemblyBuilder.EmbedAssembly( GetExecutingAssembly() ) 这样简单的东西。

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.

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).

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() ).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随遇而安 2024-07-26 18:11:18

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

  • 将引用的程序集嵌入为 托管资源,并发出程序集加载钩子,将从 加载程序集 href="http://msdn.microsoft.com/en-us/library/xc4235zt.aspx" rel="nofollow noreferrer">资源流按需提供。
  • 使用 ILMerge 使用发布后步骤来合并所有程序集一起。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文