.NET模块VS大会 [英] .NET Module vs Assembly

查看:132
本文介绍了.NET模块VS大会的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图环绕的正确答案,这我的头?有计算器上覆盖这几个话题,但与MSDN文档有所冲突。

I've been trying to wrap my head around the 'right' answer to this? there are a couple of topics on stackoverflow that covers this, but that conflicts somewhat with msdn documentation.

例如,注意在2回答他的问题图:<一href="http://stackoverflow.com/questions/1326556/what-is-a-managed-module-compared-to-an-assembly">What是一个托管模块(相较于大会)?

for example, note the diagram in the 2nd answer to his question: What is a Managed Module (compared to an Assembly)?

现在看一下MSDN图:<一href="http://msdn.microsoft.com/en-us/library/zst29sk2(VS.100).aspx">http://msdn.microsoft.com/en-us/library/zst29sk2(VS.100).aspx

Now look at the msdn diagram: http://msdn.microsoft.com/en-us/library/zst29sk2(VS.100).aspx

在MSDN图意味着一个单个文件的汇编不包括模块,而是一个清单,IL code型,元数据等。 这是比许多其他文章我读过其中规定,一个文件组件有一个模块不同。

the msdn diagram implies that a single-file assembly does not comprise of a module, but rather of a manifest, il code, type metadata, etc. This is different than many other articles i've read which states that a single file assembly has one module.

答案是什么?如果答案是两个,然后才是模块,通过集清单链接单独phyical文件?

What is the answer? If the answer is 'both', then is the module a separate phyical file that is linked via the assembly manifest?

推荐答案

每一个组件都有至少一个模块。这是一个实现细节是极不可见的。但是你可以看到,当您使用Reflection.Emit的。从样品code为 AssemblyBuilder类

Every assembly has at least one module. It is an implementation detail that's highly invisible. But you can see it when you use Reflection.Emit. From the sample code for the AssemblyBuilder class:

AssemblyName aName = new AssemblyName("DynamicAssemblyExample");
AssemblyBuilder ab = 
    AppDomain.CurrentDomain.DefineDynamicAssembly(
        aName, 
        AssemblyBuilderAccess.RunAndSave);

// For a single-module assembly, the module name is usually
// the assembly name plus an extension.
ModuleBuilder mb = 
    ab.DefineDynamicModule(aName.Name, aName.Name + ".dll");

TypeBuilder tb = mb.DefineType(
    "MyDynamicType", 
     TypeAttributes.Public);

请注意使用ModuleBuilder类,类型被添加到一个模块。该程序集可以包含多个模块是pretty的无关紧要,构建环境不支持它。不只是IDE,的MSBuild不支持它的。你不得不自己写构建脚本,以使用 Al.exe工具,组装连接器。有没有很好的理由要做到这一点,我能想到的,所有的.NET编译器已经知道如何直接生成一个单一的模块组件。 Al.exe工具是一个典型的引导工具,可能用于构建mscorlib.dll中和System.dll中。有一个循环依赖组件。

Note the use of the ModuleBuilder class, types are added to a module. That an assembly can contain multiple modules is pretty irrelevant, the build environment doesn't support it. Not just the IDE, MSBuild doesn't support it either. You'd have to write a build script yourself to use al.exe, the assembly linker. There are no good reasons to do this that I can think of, all .NET compilers already know how to generate a single module assembly directly. Al.exe is a typical bootstrapping tool, possibly used to build mscorlib.dll and system.dll. Assemblies that have a circular dependency.

这篇关于.NET模块VS大会的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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