.NET混合多文件程序集
我需要创建一个由 2 个模块组成的 .NET 程序集:1 个带有本机代码的内部模块(在 DLL 中)和 1 个外部模块(在 .netmodule 文件中)。
除了本机部分之外,这很容易做到。
C# 的编译器可以做到这一点(这就是我想要的,但是使用本机代码):
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 似乎无法往返本机代码:
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)
I need to create a .NET assembly composed of 2 modules: 1 internal (in the DLL) with native code and 1 external (in a .netmodule file).
This would be easy to do, except for the native part.
C#'s compiler can do this (this is what I want, but with native code):
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++ compiler/linker will put everything in 1 internal module.
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)
Assembly Linker only does external modules:
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)
I've also tried tweaking the IL manually, but ILDASM and ILASM don't appear able to round-trip the native code:
ildasm foobar.dll /out=foobar.il
ilasm /dll foobar.il
-lots of errors
For clarification, what I want is this:
-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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
亨克已经走上了正确的道路。您可以创建一个
.netmodule
作为输入,仅用于创建程序集。程序集是 .NET 环境中最小的执行单元。程序集可以由一个或多个物理文件组成。它可以包含多种资源:资源文件、网络模块和本机 DLL。网络模块不能单独部署,必须链接到程序集中。现在我们已经解决了这个问题,让我们尝试专注于您所追求的目标。您是否正在尝试创建多文件程序集?这是可能的。 这是一篇关于 multi 的相当古老但仍然有用的帖子 - 模块组件。或者您是否正在尝试创建可用作库的网络模块?因为这是不可能的,因为网络模块不包含程序集。
如果这不能回答您的问题,您能否更详细地解释一下您想要的最终结果是什么和/或您期望如何使用它?
Henk is already on the right track. You can create a
.netmodule
for input for creating assemblies only. An assembly is the smallest executing unit in the .NET environment. An assembly can consist of one or more physical files. It can contain several resources: resource files, netmodules and native DLLs. A netmodule cannot be deployed by itself, it must be linked into an assembly.Now that we have that out of the way, let's try to focus on what you're after. Are you trying to create a multi-file assembly? That's possible. Here's a rather old but still useful post on multi-module assemblies. Or are you trying to create netmodules that can be used as libraries? Because that is not possible, because netmodules do not contain an assembly.
If this doesn't answer your question, can you explain in a bit more detail what you want the end result to be and/or how you expect it to be used?
看起来这个问题已经在 System.Data.Sqlite 中解决了。请参阅文件 SQLite.Interop/SQLite.Interop.2010.vcxproj。
在
元素中,您需要指定
模块中的网络模块。It looks like this problem is solved in System.Data.Sqlite. See the file SQLite.Interop/SQLite.Interop.2010.vcxproj.
In the
<Link/>
element, you need to specify the netmodules in the<AdditionalDependencies/>
module.免责声明:未经测试。
您是否正在寻找正确的cl 编译器选项?
我对 link.exe 工具感到惊讶亚伯提供的链接中的内容不适合您。
Disclaimer: This is untested.
Are you looking for the correct cl compiler option?
I'm surprised the link.exe tool in the link provided by Abel didn't work for you.