.NET混合多文件程序集

标签 .net assemblies module c++-cli mixed-mode

我需要创建一个由 2 个模块组成的 .NET 程序集:1 个带有 native 代码的内部模块(在 DLL 中)和 1 个外部模块(在 .netmodule 文件中)。

这很容易做到,除了 native 部分。

C# 的编译器可以做到这一点(这就是我想要的,但是使用 native 代码):

csc /t:library /out:foobar.dll foo.cs /out:bar.netmodule bar.cs
-foobar.dll (contains assembly manifest and foo's IL)
    -internal module foobar.dll (contains foo's IL)
    -external module bar.netmodule (contains bar's IL)

C++ 编译器/链接器会将所有内容放入 1 个内部模块中。

cl /clr /LD foo.cpp /link bar.netmodule /LTCG
OR link /out:foobar.dll foo.netmodule bar.netmodule
-foo(bar).dll (contains IL for both foo and bar, as well as assembly manifest)

汇编链接器仅执行外部模块:

al /out:foobar.dll foo.netmodule bar.netmodule
-foobar.dll (only contains manifest)
    -external module foo.netmodule (contains foo's IL)
    -external module bar.netmodule (contains bar's IL)

我也尝试过手动调整 IL,但 ILDASM 和 ILASM 似乎无法往返 native 代码:

ildasm foobar.dll /out=foobar.il
ilasm /dll foobar.il
-lots of errors

为了澄清,我想要的是:

-foobar.dll (contains assembly manifest and foo's IL AND NATIVE CODE)
    -internal module foobar.dll (contains foo's IL AND NATIVE CODE)
    -external module bar.netmodule (contains bar's IL)

最佳答案

亨克已经走上了正确的道路。您可以创建一个 .netmodule 作为输入,仅用于创建程序集。程序集是 .NET 环境中最小的执行单元。程序集可以由一个或多个物理文件组成。它可以包含多种资源:资源文件、网络模块和 native DLL。网络模块不能单独部署,必须链接到程序集中。

现在我们已经解决了这个问题,让我们尝试专注于您所追求的目标。您是否正在尝试创建多文件程序集?这是可能的。 Here's a rather old but still useful post在多模块组件上。或者您是否正在尝试创建可用作库的网络模块?因为这是不可能的,因为网络模块不包含程序集。

如果这不能回答您的问题,您能否更详细地解释一下您想要的最终结果是什么和/或您期望如何使用它?

关于.NET混合多文件程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1622042/

相关文章:

c# - 哪些 .NET 4.5(或更早版本)更高级别的构造使线程更容易?

.net - 将数据库行批量发送到消息队列以进行长时间运行的操作

.net - .NET应用程序无法发送客户端证书-Win 7 vs Win XP?

c# - 如何通过 Assembly 访问泛型类型来解决它们?

c# - 我们在 GAC 中拥有同一程序集的两个版本?我希望我的客户选择哪个组件?

Python:导入包含的包

.net - 序列化 Entity Framework 对象,保存到文件,读取和反序列化

c# - 序列化组装。需要还是不需要?

module - joomla模块调用组件模型方法

powershell - 从 psm 函数的脚本 block 中定义的获取变量