//Create a Global Assembly
/*Publicly sharing functionality among different application.
*Located in Global Assembly Cache (GAC).
*Identified by globally unique name and version.
*Digital signature to ensure that it can't be tampered.
*Get smaller EXE files.
*Dynamic linking, i.e. loading on demand.
GENERATE KEY FILE: - THE STRONG NAME UTILITY (SN)
A tool is used to generate the key file incorporating a Public/Private Key pair.
We need this key pair to create a hash key for every file. The hash key is called
Public Key Token. This token allows the Common Language Runtime (CLR) to recognise
if a file has been tampered or overwritten. If the token doesn't match anymore the
file was modified.
By the time we pass the public/private key file, the private key is used to create
the public key token by encrypting the assembly name and content. The private key is
our secret and stays with us. The public key token is stored along with the public key
inside the Global Assembly's manifest. This process is called Signing the assembly.
The CLR needs the public key to decrypt the token to verify the file but not other way around.
Only with the private key we are able to create the token and nobody else can create it.
A hash token which encrypts the name and content along with the public key is called a Strong Name.
DotNet> sn -k app.snk
Version Control and Linking
The full version description consists of different parts, e.g.:
1:0:1504:18
1:0 Major and minor version
1504 Build
18 Revision
At the top of a source file we can define attributes for the key file and the version we state:
[assembly:AssemblyKeyFile("app.snk")]
[assembly:AssemblyVersion("1.0.0.0")]
While introducing the sample application we have seen how to compile our assembly to HowDoYouDo.dll.
We are now going to link the DLL with the Assembly Linker (AL) to a Global Assembly incorporating
the key file and version number:
________________
program: ga.cs
________________
using System.Reflection;
[assembly:AssemblyKeyFile("app.snk")]
[assembly:AssemblyVersion("1.0.0.1")]
public class test
{
public static void t1()
{
System.Console.WriteLine("global assembly");
}
}
Dotnet> csc /t:module /out:bin\ga.dll ga.cs
Dotnet> al /t:library /out:bin\myga.dll bin\ga.dll
[OR]
DotNet> al /t:library /keyfile:app.snk /v:1.0.0.0 /out:bin\myga.dll bin\ga.dll
Load into Assembly Cache - The Global Assembly Cache Utility (GACUTIL)
We load the Global Assembly into GAC by the use of the Global Assembly Cache Utility:
Dotnet>gacutil /i bin\myga.dll
Microsoft (R) .NET Global Assembly Cache Utility. Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
Assembly successfully added to the cache
The /i switch installs an assembly in the global assembly cache by passing the name.
It is also possible to simply copy the file directly into the GAC folder by the use of
Windows Explorer or by a command shell. Open Windows Explorer an go to C:\WINNT\assembly
and you will find the myga entry there.
Showing posts with label al. Show all posts
Showing posts with label al. Show all posts
Tuesday, December 16, 2008
Subscribe to:
Posts (Atom)