Tutorials
VB.NET 2005In this tutorial you will learn about Shared Assembly, how to Assign Strong name to an assembly, Microsoft Windows Installer 2.0, Using the Global Assembly Cache tool (Gacutil.exe), Removing an Assembly from the Global Assembly Cache, Referencing an Assembly from Global Assembly Cache, Creating a Setup project for distributing components and Creating a new merge module project.
Shared Assembly
Shared Assembly can be shared amongst several different applications that reside on the same server. This type of assembly can be used in situations where it is not necessary to install a version of an assembly for each application that uses it. For instance, it is not necessary to install the System.Windows.Forms.dll assembly for each application that uses it. It is far better to install a shared version of the assembly.
There are certain requirements that are placed upon shared assemblies. The assembly needs to have a globally unique name, which is not a requirement of application-private assemblies. Strong names are used to create a globally unique name for an assembly. As that assembly is shared, all references to the shared assembly are checked to ensure the correct version is being used by an application. Shared assemblies are stored in the Global Assembly Cache(GAC), which is usually located in the assembly folder in the windows directory( for example in Windows XP, C:\Windows\assembly).
Assigning Strong name to an assembly
Strong name is not a name as such but is, in fact, a public key that has been generated by the author of the assembly in order to uniquely identify the assembly. A strong name is what is used to ensure that your assembly has a unique signature compared to other assemblies that may have the same name. Strong names were introduced to combat the situation where a developer would have created a component and another developer releases a different assembly with the exactly the same name as the original component, and could be mistaken for being new version of the original component. Without strong names users would be confused and unable to identify the problem.
A strong name is based on public-private key encryption and creates a unique identity for the assembly. A key pair can be created and can be used to define a strong name by using the SN tool included in the .NET Framework SDK. The public key is stored in the identity section of the manifest. A signature of the file containing the assembly's manifest is created and stored in the resulting PE file. The .NET Framework uses these two signature when resolving type references to ensure that the correct assembly is loaded at runtime. A strong name is indicated in the manifest by the .publickey directive in the .assembly section.
To create a key pair
1) At the command prompt, type the following command:
sn -k
sn -k sgKey.snk
4) If you intend to delay sign an assembly and you control the whole key pair (which is unlikely outside test scenarios), you can use the following commands to generate a key pair and then extract the public key from it into a separate file. First, create the key pair:
sn -k keypair.snk
5) Next, extract the public key from the key pair and copy it to a separate file:
sn -p keypair.snk public.snk
Once the key pair is created, the developer must put the file where the strong name signing tools can find it. When signing an assembly with a strong name, the Assembly Linker (Al.exe) looks for the key file relative to the current directory and to the output directory. When using command-line compilers,the key can be copied to the current directory containing the code modules.
If an IDE, such as Visual Studio .NET is being used, to sign an assembly with a strong name, it is important to understand where the IDE looks for the key file. For example, Visual Basic .NET looks for the key file in the directory containing the Visual Studio Solution, whereas the C# compiler looks for the key file in the directory containing the binary. Put the key file in the appropriate project directory and set the file attribute as follows:
< Assembly: AssemblyKeyFileAttribute("key.snk") >
Assigning Strong Name to an Assembly
There are two ways to sign an assembly with a strong name:
The developer must have a cryptographic key pair to sign an assembly with a strong name.
To create and sign an assembly with a strong name using the Assembly Linker
To sign an assembly with a strong name using attributes
Adding an Assembly into the Global Assembly Cache
There are two ways to install an assembly into the global assembly cache:
This is the recommended and most common way to add assemblies to the global assembly cache. The installer provides reference counting of assemblies in the global assembly cache, plus other benefits.
Using the Global Assembly Cache tool (Gacutil.exe)
You can use Gacutil.exe to add strong-named assemblies to Adding predefined installation components to your project.the global assembly cache and to view the contents of the global assembly cache.
Note Gacutil.exe is only for development purposes and should not be used to install production assemblies into the global assembly cache.
To install a strong-named assembly into the global assembly cache
Removing an Assembly from the Global Assembly Cache
The .NET Framework SDK also provides a Windows shell extension called the Assembly Cache Viewer (Shfusion.dll), which can be used to remove assemblies from the global assembly cache.
Next Page: Shared Assembly - Page 2
|
Hi , It was really a good artical to know concept of assembly in practical scenario.I have read lot of documents releade to assembly but all are more theorytical then practical> Thanks, Sourabh |
| Excellent yaa ..good work ..keep going |
| very use full thank you for your work |