Chapter 2 of "CLR Via C#"

Table of contents

1. Classification of books and key points of the whole book (simplified as much as possible)

  1. Book classification

  2. Key points of the book

2. Chapter 2 Generate, package, deploy and manage applications and types

  1. The focus of this chapter (simplify as much as possible)

  2. Chapter Contact

    2.1 One of two:

    2.2 Two of three

3. Detailed explanation of this chapter

  1.NET Framework deployment target

  2. Generate the type into the module

  3. Response file

  4. Metadata Overview

  5. Merge modules into assemblies

  6. Assembly version resource information

  7. Language and culture

  8. Simple Application Deployment (Privately Deployed Assemblies)

  9. Simple management control

Four, the problem

  1. What is the exe file generated by C# compilation?

5. Mind map


1. Classification of books and key points of the whole book (simplified as much as possible)

  1. Book classification

        Theoretical papers mainly talk about the foundation of CLR, C# and .Net.

  2. Key points of the book

        From the shallower to the deeper, see the essence of CLR and .NET, know what it is, penetrating into it, explore the mechanism of CLR and .NET, and know why.

2. Chapter 2 Generate, package, deploy and manage applications and types

  1. The focus of this chapter (simplify as much as possible)

        This chapter focuses on explaining how to generate assemblies for use only by your own application.

  2. Chapter Contact

    2.1 One of two:

        The first chapter briefly introduces metadata and assemblies, and the second chapter will introduce them in more detail.

    2.2 Two of three

        Chapter 3 details more advanced concepts, including building and using assemblies so that the types contained within them can be shared by multiple applications.

3. Detailed explanation of this chapter

        Try to use diagrams and metaphors to record. Document it in a way that will teach others.

  1.NET Framework deployment target

Stable         is required to install updates . When installing new applications, it is necessary to ensure that the old applications continue to be compatible and run.

        Installation and uninstallation complexity is less. For example, the Windows installer application will install files to other places, such as the registry, desktop shortcuts, etc. Therefore, when the application is transferred, it is not possible to just copy and paste the program installation location file, but also to adjust the registry and so on. And uninstallation does not necessarily guarantee a clean uninstallation, and the registry is not necessarily uninstalled.

        Security is better. Applications must be integrated into the system to allow users to allow or disallow code access to their own system resources.

  2. Generate the type into the module

public sealed class Program{

      public static void Main(){

             System.Console.WriteLine(“Hi”);

      }

}

        This application defines the Program type , which has a public static method named Main . Another type System.Console is referenced in Main . System.Console is a type implemented by Microsoft, and the IL code for implementing each method of this type is stored in the MSCorLib.dll file . In summary, the application defines a type and also uses types provided by other companies.

        After putting the above code into the source code file ( Program.cs ) , execute the command to run:

        csc.exe /out:Program.exe /t:exe /r: MSCorLib.dll Program.cs

        This command instructs the C# compiler to generate an executable named Program.exe of type Win32 console application ( /t [ arget ] :exe ) . r[eference]: MSCorLib.dll tells the compiler to search for the MSCorLib.dll assembly for the System.Console.WriteLine method that is not defined in the source code (in fact, it can be omitted, because it is used).

        Windows supports three types of applications :

  1. The Console User Interface (CUI) uses the /t:exe switch.
  2. The Graphical User Interface (GUI) uses the /t:winexe switch.
  3. Windows Store apps /t:appcontainerexe switch.

  3. Response file

        A response file is simply a text file with a set of command line switches that, when run, execute a number of commands. Equivalent to the integration command. Called with @ , it is the rsp file .

        csc.exe @MyProject.rsp CodeFile1.cs CodeFile2.cs

        .NET Framework will have a global CSC.rsp response file, which contains many necessary references, such as: /r:System.dll, /r:System.Date.dll.

  4. Metadata Overview

        Metadata is a binary data block composed of several tables . There are definition tables, reference tables, and list tables .

        Definition table: A table that records definitions of modules, source code types, methods, etc. There are ModuleDef records for module identification (record module files and extensions, IDs, etc.), and TypeDefs identify type names, base types, flags, etc.

        Reference table: A table that records references to assemblies, modules, type methods, etc.

  5. Merge modules into assemblies

        Program.exe is not only a PE file, but also an assembly . An assembly contains a manifest, which is a collection of metadata tables. The CLR operates the assembly , first loads the file containing the "manifest" metadata table, and then obtains the names of other files in the assembly according to the manifest. An assembly can be viewed as a logical EXE or DLL .

        Assemblies can be ordered to compile common and uncommon types into different modules.

  6. Assembly version resource information

        Assemblies can customize attributes to set various versions.

  7. Language and culture

        Assembly can specify a specific language culture, such as English, French and so on.

  8. Simple Application Deployment (Privately Deployed Assemblies)

        VS will package all the assemblies of the application into an .appx file. When a user installs, the CLR loads assemblies from the directory containing all assemblies. Add start shortcut and more.

  9. Simple management control

        Don't learn it, use it later.

Four, the problem

  1. What is the exe file generated by C# compilation?

        Answer: The exe file is a standard PE (Portable Executable) file, which can be loaded and run on a 32- or 64-bit Windows computer. Managed PE files contain PE32(+) headers, CLR headers, metadata, and IL.

5. Mind map

 

おすすめ

転載: blog.csdn.net/weixin_51374560/article/details/128807200