The BizTalk project has been in operation for more than half a year, and each project uses the GAC and Sn tools. At that time, the "master" just gave a rough talk about their role, that is, the DLL should be shared, if anyone can access the service quickly, add the DLL signature and install it to the global cache, while the Sn. EXE is a tool for generating key files. today, I just want to find something online.ArticleImprove and summarize the relevant knowledge.
GlobalProgramSet cache (GAC) isCodeCache, which is available on any machine with the installed CLR. an assembly designed to be shared across applications can be stored here, but it must have a strong name. note that the Assembly installed with GAC must have a matched Assembly name and file name, excluding the file extension (therefore, myassembly must be consistent with myassembly. DLL or myassembly.exe pairing ).
DLL hell
Windows applications are often dragged down by Dynamic Link Libraries, which is a "DLL hell" problem, A component of an application will be overwritten by incompatible components of other applications. As a result, the application that is disturbed cannot work correctly. these problems are difficult to diagnose, because they only occur after the problem component is installed for a period of time. the DLL hell issue of Visual Basic applications is even more notorious because visual basiC LanguageCompared with otherProgramming LanguageDeveloped applications have greater external relevance. Microsoft's. Net Plan is expected to use a new type of distributed unit assembly (assembly) to ease this serious problem.
Assembly Mechanism
From a programming perspective, an assembly is functionally equivalent to a Java package: it provides allocable libraries for related classes and defines their scopes. for those who are not familiar with Java, when developing an application. net is equivalent to a DLL file in COM, But Assembly is composed of multiple files.
Assemblies can be self-documented through so-called manifest, which is a typical feature that is better than DLL. the List is included in the Assembly. It consists of metadata about the export class of the assembly, external attachment required by these classes, permissions required to use the assembly, and version control information of such dependency. in. in the. NET Framework, Assembly provides a public name for versions, classes, and individual files that cannot be versioned. in this way, you do not have to check multiple files to determine the version of the components installed on the system. This is the most annoying thing in the past .. net version control feature can almost completely eliminate DLL hell.
Private assembly and public assembly
By default ,. net assembly is private, which means they can only be used by an application. private assembly should be installed in the folder where the application is located or one of its subfolders. microsoft wants the majority. NET developers can adopt private assemblies, and in fact it encourages people to do so.
However, this may bring about a potential problem: the user's hard disk may become messy because of multiple copies of the same private assembly, which is really ironic, it sounds like Com is easier to solve this problem. microsoft responded to the above criticism in this way: "the hard disk is cheap, just buy a bigger one. "Fortunately, you can easily convert a private assembly into a public assembly without re-compiling or editing the code.
Benefits
The main difference between a shared assembly and a private assembly is that the former is usually stored in a specially named Global Assembly Cache (GAC. GAC is sometimes referred to as global assembly store in Microsoft documents, probably because the latter is a bit nice for short.
GAC can store multiple versions of the same Assembly. This is what Microsoft calls "side by side deployment. this function almost eliminates the possibility of installing incompatible shared components for applications and affecting other applications. This is certainly good news for developers.
The customer assembly can specify which version or version of the shared Assembly it is compatible. if the version requirements of the client program cannot be met. net does not load any server assembly. by the way ,. the Assembly version of. NET is in the format of a four-digit number, for example, the main version number. minor version number. create a version number. revision version.
By default. an assembly is considered only compatible with shared assembly with the same main version and minor version. however, the runtime loader preferentially loads an assembly with a higher creation version or revision version number than the customer version. If such an assembly exists, it will automatically provide repair support. this default behavior is not always what you want, so programmers or system administrators can define custom version control policies, for example, forces the loading of a specific version or disables the loader to mount an assembly with a later version or a later version.
In Beta 1, version control policies are included in some XML files, which do not reside in the application directory or be saved in the Windows directory. these XML files define version policies related to specific software and version control policies within the system.
Name
You can name a private assembly as long as its name is unique within the application. on the other hand, a globally unique identifier is required for public assembly. net runtime can recognize them. com class ID and prog ID Are Gone with the Wind. currently, shared Assembly adopts the so-called strong name naming mechanism. strong name comes from standard public key encryptionAlgorithm. The developer uses a private key to "sign" the Assembly and provides a public key for the customer to use the Assembly. The public key is then part of the strong name of the Assembly.
Using the command line compiler to sign the Assembly requires some command line command options, so this is also a heavy task. Fortunately, Visual Studio. NET can automatically complete these tasks for programmers.
Small assembly for major events
Microsoft finally admitted the existence of the DLL hell problem, and realized that this problem can be remedied only by applying control policies at the operating system level. after the registry and support for a single component of the COM application, it seems that Microsoft is on the right path. in fact, with the Assembly mechanism, install.. NET applications can be simply copied by using the xcopy command!
SN. exe tool
The strong name tool helps you use the strong name to sign the program set. sn.exe provides options for key management, Signature generation, and signature verification.
Vs2005 strong name example
Use sn.exe to generate a key file samplekey. SNK. the original English text of this file is called string name key file, and then the encryption algorithm is used according to samplekey. SNK generates a samplekeypublic. SNK. finally, according to samplekeypublic. SNK extracts a public key token. The public key token is a 16-bit combination of numbers and letters. The general process is as follows:
Samplekey. SNK -- according to certain algorithms --> samplekeypublic. SNK ----> Public Key token, so we only need samplekey. SNK and Public Key token. samplekeypublic. SNK is useless. because samplekeypublic. SNK's contribution has been completed.
The actual operation is as follows:
1. Open the SDK command prompt or Visual Studio 2005 command prompt in vs2005, instead of Windows cmd.
2. Enter Sn-K samplekey. SNK. The obtained file is in the current folder of the command prompt (Microsoft calls the folder a directory rarely, and the most important point is folder)
3. Enter Sn-P samplekey. SNK samplekeypublic. Snk (extract the public key from samplekey. SNK and save it to the samplekeypublic. SNK file)
4. Enter Sn-T samplekeypublic. SNK to get the public key token.
Open vs2005, find the project, right-click "project name", find "properties", and there is a "signing" tab in "properties", and hook "sign the Assembly ", then choose a strong name key file. after the operation is complete, remember to save and compile your DLL so that it can be dragged to GAC. GAC is "Global Assembly Cache", which is why your project's bin Folder does not have system. data, you can reference the reason, because the program will automatically find the GAC, the location of GAC in Win 2003 is "C: \ WINDOWS \ assembly ".