Relationship of the. Net Framework's managed modules to assemblies

Source: Internet
Author: User

First, the basic concept:--managed module: A standard 32 portable execution Body (PE32) file or a standard 64-bit portable execution body (pe32+) file. Generated by a source code file created in any language that supports the CLR, and then compiled with the appropriate compiler check syntax and parsing sources. As follows:--assembly: the logical combination of one or more modules/resource files.    Assemblies are the smallest unit of reuse, security, and version control. You can think of. exe and. dll files as an assembly where the. exe file is an assembly that executes itself, and the. dll is run after it is loaded by another assembly. Ii. analogy between module and assembly concept a project's development team will have one or more "members" who will have a person in charge. People outside the team have to deal with the team and they just need to know who is responsible for the team. Because this person in charge "member" knows all the situation inside the team. In many cases, people outside the team address the team with the name of the person in charge.    Here, the team is a logical concept, not a specific person or resource. Team = Assembly Owner = Main module (the difference from normal module is explained below) member = Normal module In many cases, we use the characteristics of the main module, such as name, to address an assembly. That is (called a team by the character of the owner "member") III. module and assembly Generation 1, CS file Suppose I have two. cs's class library file, and a. cs file that contains the main method, are placed in the D:\test folder. are: Cat.cs:namespace Animal    {        {    }Dog.cs:namespace Animal    {        {    }Program.csPublic Class program    {new Cat (). Print (); 2. Generating a class library assembly you can now generate the corresponding modules for these two. cs files, using the csc.exe compiler: Csc/t:module/out:d:\test\cat.netmodule d:\test\cat.cscsc/t:module/ Out:d:\test\dog.netmodule d:\test\dog.cs  This will generate two common modules in D:\test directory:cat.netmoduledog.netmodule  Because the CLR is loaded with an assembly as the smallest unit, in order for the Program.cs file to be able to call Cat.netmodule and dog.netmodule/properly, the two files are now generated as an assembly. Because this assembly is loaded by another assembly, the resulting file name can be: Animal.dllcsc/out:d:\test\animal.dll  /t:library/addmodule:d:\test\ Cat.netmodule;d:\test\dog.netmodule after executing this command, the modules in the animal.dll  are generated in the D:\test directory: Main Module (owner): Animal.dll Normal Module (member): Cat.netmodule, Dog.netmodule. Assembly (Team): Consists of the main module Animal.dll and the ordinary module Cat.netmodule, Dog.netmodule. But in general we will refer to Animal.dll as an assembly. Especially in the case of the IDE's Visual Studio build, because in the IDE's default generated DLL, each module has been included in the DLL, in addition to the DLL, and there are no other module files. Here we can run the command: Csc/out:d:\test\animal.dll/t:library D:\test\Cat.cs D:\test\ Dog.cs generates the Animal.dll file directly, the Cat.netmodule and Dog.netmodule files are no longer generated;  3, exe call DLL name: CSC/OUT:D:\TEST\PROGRAM.EXE/R :D: \test\animal.dll D:\test\Program.cs     will generate Program.exe executable file in D:\test Note: The Animal.dll file here represents theis an assembly, and if the assembly consists of multiple files, the other files must be guaranteed to exist or the compilation will fail. If the assembly consists of the main module Animal.dll, the ordinary module cat.netmodule and Dog.netmoudle, it is necessary to ensure that the three files exist simultaneously.    can be executed directly on the command line: Program.exe input results:    dog    cat 4, the role of multiple modules in an assembly     The CLR is loaded as an assembly. However, the CLR loads only the modules that are referenced, and the modules that are not referenced are not loaded. Therefore, you can divide the assembly into multiple modules, and when you run a program, you can reduce the size of the loaded assembly file, as long as you guarantee that the referenced module exists, especially when the assembly is loaded over the network. Example:    Modifying a Program.cs file so that it no longer references a type in a Cat.cs filePublic Class program    {//New Cat (). Print ();}Recompile Program.cs file: Csc/out:d:\test\program.exe/r:d:\test\animal.dll D:\test\Program.cs now in D:\ The test folder has the following files: Run Program.exe, result: Now Cat.netmodule Delete: Run Program.exe, Result: The CLR does not load cat.netmodule, so it doesn't matter if the normal module doesn't exist.

Relationship of the. Net Framework's managed modules to assemblies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.