What the assembly means
I. An assembly is a collection that contains one or more type definition files and resource files. It allows us to analyze the logical and physical representations of reusable types.
As you define a project Xxproject, the project has many files (classes, forms, interfaces, resources, etc.), compiled to generate a DLL file, which is the assembly.
When you use this assembly, you can get all the things in the Assembly (classes, forms, interfaces, resources) by referencing and changing the program.
The features of the Assembly are as follows:
1. The Assembly defines a reusable type
2. Assembly ID has a version number
3. The assembly can contain security information related to it
Two. Reasons for using assemblies (that is, the reason for using multi-file sets):
1. The types can be implemented in separate files, allowing files to be downloaded incrementally in an Internet environment
2. You can add resources or data files to an assembly as needed (data files can be task formats: text files, spreadsheets, Word documents, and so on)
3. It can be that the assembly we created contains some types implemented in different programming languages.
Note: VS. NET trick after the feature development environment itself does not support the creation of multi-file assemblies, if you need to create a multi-file assembly, you must resort to command-line tools.
Csc/t:module Rut.cs//Generate Rut.netmodule file
Csc/out:uniontype.dll/t:library/addmodule Rut.netmodule Fut.cs
Generate the UnionType.dll class library file Run.netmodule file as part of the Assembly to treat
Three. PROGRAM linker
PROGRAM linker: Assembly linker is AL.exe
Usage Prerequisites:
The Assembly linker is useful when the assembly we are creating contains modules from different compiler builds, and the compiler used does not support a command-line switch similar to/addmodule in C #, or when the module is built without knowing the assembly's packaging requirements.
Usage examples:
Csc/t:module Rut.cs
Csc/t:module Fut.cs
Al/out:uniontype.dll/t:library Fut.netmodule Rut.netmodule
Four. Adding a resource file
1. To add a resource file using csc.exe:
/resource will embed the specified resource file into the resulting assembly PE file and update the contents of the Manifestresourcedef table.
/linkresource will add an item to the MANIFESTRESOURCEDEF and filedef manifest table to point to a separate resource file.
2. To add a resource file using AL.exe:
/embed[resource]: This command line accepts any type of file and embeds its contents into the resulting PE file. Also, the Manifestresourcedef table in the list is updated to reflect the existence of the resource.
/link[resource]: This command will only update 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. To embed a WIN32 resource in an assembly:
You do this by specifying a path to the. res file by AL.exe or csc.exe add/win32res command-line switches.
Add the/win32icon command-line switch by AL.exe or csc.exe and specify an. ico file path to implement.
V. C # assembly version information:
The version number consists of four parts: Major version, minor version, build version, revision number
Example: 2.5.719.2 the major and minor version numbers constitute a "public-facing" version, the third version number 719 represents the build version of the assembly, and the last version number 2 represents the revision of the build version.
Three related version numbers of an assembly:
1, assemblyfileversion: This version number is stored in the WIN32 version of the resource, it is only an auxiliary information.
2, AssemblyInformationalVersionAttribute: This version number is also stored in the WIN32 version of the resource, only auxiliary role.
3. AssemblyVersion: This version number is stored in the AssemblyDef Inventory metadata table. This version number is very important and it is used to uniquely identify an assembly.
Vi. Language and culture:
Creating a satellite assembly containing code is not advocated, but it is still possible to do so. If we wish, we can still use the System.Reflection.AssemblyCultureAttribute custom feature instead of the AL.exe/culture command-line switch to specify the language culture. Examples are as follows:
Set the language culture of the assembly to Swiss German
[Assembly:assemblyculture ("De-ch")]
Typically, the assembly that we create should not reference a satellite assembly. That is, the AssemblyRef entry for an assembly should point to a language culture-neutral assembly. If you want to access a type or member of a satellite assembly, we should use reflection techniques.
Satellite assemblies: Assemblies that identify language-specific files are called satellite assemblies.
Vii. Shared assemblies:
1.. NET Framework supports two types of assemblies:
Weakly named assemblies: weakly named assembly
Strong-Named assemblies: strongly named assembly
The real difference between the two is that the strong-named assembly has a public/private key pair signature for the publisher, where the public key/private keys pair uniquely identifies the publisher of the Assembly.
A strong named set contains four attributes that uniquely identify the assembly: file name (without extension), version number, language culture identifier, and a public key identifier.
Example: "mytypes,version=1.0.8123.0,culture=neutral,publickeytoken=b77a5c561934e089"
2. Strong naming utility:
Strong Name utility is the SN.exe and. NET Framework SDK, as well as Visual Studio. NET to publish a tool together.
Example: Sn–k Mycompany.keys
This command tells SN.exe to create a file named Mycompany.keys. The Mycompany.keys file will contain a pair of public keys and private keys stored in binary format.
To view the public key: (You must perform the following two steps)
Sn–p Mycompany.keys Mycompany.publickey
SN–TP Mycompany.publickey
To create a strong-named assembly:
[Assembly:assemblykeyfile ("Mycompany.keys")]
3. Two ways to deploy an assembly: private deployment Mode and global deployment method
Private deployment The assembly is deployed in the application's base directory and its subdirectories, and weak-named assemblies can only be privately deployed.
The global deployment method deploys the assembly to some of the CLR's known locations. Strong-Named assemblies can be either privately deployed or globally deployed.
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 identifier is a 4-byte numeric value whose high byte represents the type of token (0x01 = TypeRef, 0x02 =typedef, 0x26 = filedef, 0x27 = ExportedType)
To make the C # assembly that we created appear in the. NET tab in the list, you can add the following subkey to the registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\. Netframework\
C # programming (83) meaning of----------Assembly