. NET Beauty Reading notes 6

Source: Internet
Author: User

Assembly definition

Under the. NET Framework, high-level languages such as C # are compiled with the resulting file as an assembly (with a suffix of. exe or. dll).

Composition of assemblies
    • Pe/coff header enables the Windows operating system to load and run
    • The CLR header tells the system to be. NET assembly
    • Manifest (manifest) assembly identity can be viewed by anti-compilation
    • Metadata content includes modules, types, and so on that the assembly contains
    • CIL code
    • Resource file
Assembly Anti-compilation
    1. Compile the CS file with the "vs Developer command Prompt".
      csc MyClass.csCompile commands, parameters that can be set for compilation
parameter type /tr>
/t: library compiled as DLL library file
/out: myclass.dll output file
/r: myclass.dll referencing assemblies
/addmodule: myfirstmoduldle.netmodule load module
/resource: resourcedemo.resx load Resource
/keyfile: key encryption key
    1. Assembly Anti-compilation CIL code
      ildam /out:1.txt MainClass.exeYou can decompile the MainClass.exe assembly to a 1.txt file.
instruction Name Sample Example meaning
. assembly extern mscorlib Referenced assemblies
. Assembly MainClass Current Assembly
. module MainClass.exe Current module
. file Myfirstmodule.netmodule Reference module
Multi-Module assemblies

Assemblies compiled with VS are all but module assemblies, but one assembly can contain multiple modules. The new MyFirstMOdule.cs MySecondModule.cs file is compiled as a module, MainClass references.

using System;class MyFirstModule{    public static void Hello()    {        Console.WriteLine("Hello,I am from Module 1");    }}
using System;class MySecondModule{    public static void Hello()    {        Console.WriteLine("Hello,I am from Module 2");    }}
using System;class MainClass{    static void Main()    {        MyFirstModule.Hello();    }}

Compile Commands csc /t:module /out:MyFirstModule.netmodule MyFirstModule.cs , csc /t:module /out:MySecondModule.netmodule MySecondModule.cscsc /addmodule:MyFirstModule.netmodule,MySecondModule.netmodule MainClass.cs
Using the benefits of the module, the runtime can delete modules that are not needed, thus reducing the load on the module. (However, the author recommends using multiple small assemblies)

Strong Name Assemblies
    1. Version of the Assembly
      Specifies the version for the Assembly, which makes it easy to change later.
    2. Use the public/private key to prevent the assembly from being tampered with
      Compile your own class library with a key to prevent others from faking it and not running it. This is a bit confusing, if you decompile the encrypted DLL file to txt, modify the content in the and extension IL, and then edit it as a DLL, you can tamper with it.

      Global Assembly Cache

      Adding multiple referenced DLL assemblies to the global cache increases efficiency. Add buffers gacutil i MyClass.dll and exit buffersgacutil u MyClass.dll

. NET Beauty Reading notes 6

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.