Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What does C # assembly mean?

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what the C# assembly refers to". The content is easy to understand and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn the article "what does the C# assembly mean?"

1. Some basic concepts of C # assemblies:

An assembly is a collection that contains one or more type definition files and resource files. It allows us to separate the logical and physical representations of reusable types.

An assembly is a reusable unit that enforces version and security policies. It allows us to divide types and resources into different files so that users of the assembly can decide which files to package and deploy together. Once CLR loads the file that contains the manifest in the assembly, it can determine which of the other files in the assembly contain the types and resources that the program is referencing. The consumer of any assembly only needs to know the name of the file that contains the manifest. The division of files is transparent to users and can be changed in the future without disrupting the behavior of existing applications.

Features of C # assemblies:

1. Assemblies define reusable types.

2. The assembly identity has a version number.

3. Assemblies can contain security information related to them.

Second, multiple filesets:

There are three reasons for using multiple filesets:

1. Types can be implemented in different files, thus allowing files to be downloaded incrementally in the Internet environment.

You can add resources or data files to the assembly as needed. Data files can be in any format: text files, Excel spreadsheets, Word tables, or any format we like.

3. It allows us to create assemblies that contain types implemented in different programming languages.

Note: the Visual Studio .NET integrated development environment (Integrated development environment, or IDE) itself does not support the creation of multifile assemblies, and if you need to create multifile assemblies, you must resort to command line tools.

Two source code files: Rut.cs (containing rarely used types) Fut.cs (containing frequently used types)

Csc / t:module Rut.cs / / generate Rut.netmodule files csc / out:UnionType.dll / t:library / addmodule Rut.netmodule Fut.cs / / generate UnionType.dll class library files Run.netmodule files are treated as part of the assembly

3. Program linker:

Program linker: Assembly Linker is AL.exe

1. Premise of use:

The assembly linker is very useful if we are creating an assembly that contains modules generated by different compilers, and the compiler we are using does not support command line switches like the one in C# / addmodule, or if the module is generated without knowing the packaging requirements of the assembly.

2. Use examples:

Csc / t:module Rut.cs csc / t:module Fut.cs al / out: UnionType.dll / t:library Fut.netmodule Rut.netmodule

IV. Addition of resource files

1. Use csc.exe to add resource files:

/ resource embeds the specified resource file in the resulting assembly PE file and updates the contents of the ManifestResourceDef table.

/ linkresource will add an entry to the ManifestResourceDef and FileDef inventory tables to point to a separate resource file.

2. Use AL.exe to add resource files:

/ embed [resource]: this command line accepts any type of file and embeds its contents in the resulting PE file. At the same time, the ManifestResourceDef table in the list is updated to reflect the existence of the resource.

/ link [resource]: this command will update only the ManifestResourceDef and FileDef tables in the manifest to reflect the existence of the resource and identify which file of the assembly contains the resource file. The resource file itself is not embedded in the assembly PE file, it remains independent and must be packaged and deployed with other programs.

3. Embed Win32 resources in the assembly:

Specify a .res file path through the AL.exe or csc.exe add / win32res command line switch.

This is done by AL.exe or csc.exe adding the / win32icon command line switch and specifying an .ico file path.

5. C# assembly version information:

The version number consists of four parts: major version number, minor version number, generated version number, and revision number.

Example: 2.5.719.2 the major version number and the minor version number constitute the version part of "facing the public". The third version number 719 represents the generated version of the assembly, and * a version number 2 indicates the revised version of the generated version.

Three related version numbers of an assembly:

1. AssemblyFileVersion: this version number is stored in the Win32 version resource, and it is only an auxiliary information.

2. AssemblyInformationalVersionAttribute: this version number is also stored in the Win32 version resource and plays an auxiliary role only.

3. AssemblyVersion: the version number is stored in the AssemblyDef cleaning unit data table. This version number is very important and is used to uniquely identify an assembly.

VI. Language and culture:

Creating satellite assemblies that contain code is not recommended, but it is still possible. If we prefer, we can still use the System.Reflection.AssemblyCultureAttribute custom feature instead of AL.exe 's / culture command-line switch to specify the language and culture. Examples are as follows:

/ / set the language and culture of the assembly to Swiss German

[assembly: AssemblyCulture ("de-CH")]

In general, the assemblies we create should not reference satellite assemblies. That is, the AssemblyRef entry of an assembly should point to an assembly that is culturally neutral. If you want to access a type or member in a satellite assembly, we should use the reflection technique.

Satellite assembly: an assembly that identifies a specific language file is called a satellite assembly.

7. Shared assemblies:

Two types of assemblies supported by the 1..NET framework:

Weakly named assemblies: Weakly named assembly

Strongly named assemblies: Strongly named assembly

The real difference between the two is that a strongly named assembly has a publisher's public / private key pair signature, where the public / private key pair uniquely identifies the assembly's publisher.

A forced naming set contains four features that uniquely identify the assembly: the file name (no extension), the version number, the linguistic and cultural identity, and a public key identity.

Example: "MyTypes,Version=1.0.8123.0,Culture=neutral,PublicKeyToken=b77a5c561934e089"

2. Strong naming utility:

Strong Name Utility is a tool released by SN.exe and the .net framework SDK, as well as Visual studio .net.

Example: SN-k MyCompany.keys

This command tells SN.exe to create a file called Mycompany.keys. The Mycompany.keys file will contain a pair of public and private keys stored in binary format.

View the public key: (the following two steps must be performed)

SN-p MyCompany.keys MyCompany.publickey

SN-tp MyCompany.publickey

Create a strong named assembly:

[assembly: AssemblykeyFile ("MyCompany.keys")]

3. Two deployment modes of assemblies: private deployment and global deployment

Private deployment deploys assemblies under the application's base directory and its subdirectories, while weakly named assemblies can only be deployed privately.

The global deployment approach deploys assemblies in places that CLR knows. Strong-named assemblies can be deployed either privately or globally.

4.System.Reflection.AssemblyName class:

With it, we can easily create an assembly name and get the various parts of an assembly name. Public instance properties: such as CultureInfo, FullName, KeyPair, Name, and Version. This class provides several public instance methods, such as GetPublicKey, GetPublicKeyToken, SetPublicKey, and SetPublicKeyToken.

VIII. Other

The metadata identity is a 4-byte numeric value whose high-order bytes indicate the type of tag (0x01 = TypeRef, 0x02 = TypeDef, 0x26 = FileDef, 0x27 = ExportedType)

To make the C# assembly we created appear in the list on the .NET tab, you can add the following subkey to the registry: HKEY_LOCAL_MACHINE\ SOFTWARE\ Microsoft\ .NET Framework\

The above is all the content of the article "what does the C# Assembly mean?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report