Académique Documents
Professionnel Documents
Culture Documents
Net
When we create a project in Visual Studio .Net and compile it, assemblies are created. These assemblies are the fundamental units of applications in the .NET Framework. An assembl can contain classes, structures, interfaces, and resources that an application re!uires. When we compile a pro"ram, the compiler translates the source code into the Intermediate Language code (IL). #n addition to translatin" the code into #$, the compiler also produces metadata about the pro"ram durin" the process of the compilation. %etadata contains the description of the pro"ram, such as the classes and interfaces, the dependencies, and the &ersions of the components used in the pro"ram. The #$ and the metadata are linked in an assembl . An #$ and metadata e'ist in portable executable file(E)E*+$$,. #f we look at an project folder, we will find a bin folder that contains, sa m project.dll* m project.e'e and m project.pdb files. The m project.dll* m project.e'e is the assembl , and m project.pdb ( pro"ram database , file contains debu""in" information for the assembl . The .pdb file also contains information the linker can use when debu""in" the assembl . So, when we create and compile the project in VS.Net, the assembl is automaticall "enerated and copied into the application-s bin director . An assembl also contains an assembly manifest that contains the assembl metadata. This metadata contains information about the assembl &ersion, its securit identit , the resources re!uired b the assembl and the scope of the assembl . This information is stored within the assembl file (+$$*E)E, itself. Note that the assembl contains two t pes of metadata. .ne, is the t pe metadata and the other is the assembl metadata.
!y use Assemblies"
The "oal of the assembl model is the elimination of +$$ 4ell. 5nder the current 0.%*0.%6 model, a catalo" of +$$s is centrali7ed in the Windows 1e"istr . When a new &ersion of a +$$ is published, the re"istr re8references the catalo" to point to the new +$$. This centrali7ed re"istration paradi"m makes it challen"in" for multiple applications to depend on the same +$$. %ost often, the application binds to a +$$ in a centrali7ed location, rather than run multiple &ersions of a component b usin" side8b 8 side e'ecution. The .NET Framework makes it eas to run multiple &ersions of a component because it stores assemblies in local application directories b default. This isolates the assembl from use b an other application and protects the assembl from s stem chan"es.
#ypes of Assemblies
Assemblies can be pri$ate or s!ared. The assembl which is used b a sin"le application is called as pri$ate assembly. Suppose we ha&e created a +$$ which encapsulates business lo"ic. This +$$ is used b the client application onl and not b an other application. #n order to run the application properl the +$$ must reside in the same folder in which the client application is installed. Thus the assembl is pri&ate to the application. Suppose we are creatin" a "eneral purpose +$$ which pro&ides functionalit to be used b a &ariet of applications. Now, instead of each client application ha&in" its own cop of +$$ we can place the +$$ in -"lobal assembl cache-. Such assemblies are called as s!ared assemblies. When we create an application in Visual Studio.Net that uses a component, which is not in the 9A0, the assembl is automaticall copied to the project:s bin folder. So, if we simpl the cop the project:s bin folder, the assembl for the component is copied as well. Since the files the application needs are in the same folder, the application can run without re"istration.
When ou ha&e multiple applications usin" one assembl , ou ha&e to deplo the assembl to the bin director of each application.
+ummary&
Assembl ph sicall e'ist as +$$s or E)Es. An assembl consists of a manifest and the portable e'ecutables (/E,. 9lobal assembl cache is nothin" but a special disk folder where all the shared assemblies will be kept.
+tep - & )enerating *ryptograp!ic 3ey Pair using t!e tool +N.Exe
Now, we will use the SN tool to "enerate the cr pto"raphic ke pair, which is located in the ?bin subdirector , where the .NET Framework Solution +e&eloper ;it (S+;, is installed. We will open the +.S prompt. The command8line statement format is> sn 8k D0>?G+irector To/lace;e H?G;e NameH.ke D Ne't, create a director named m ke s in 0>? so that ou can easil locate the ke and access the ke from the command prompt. N2#E& For most users, the .NET tools are located in 0>?/ro"ram Files?%icrosoft.NET?FrameworkS+;?2in. T pe the followin" at the command prompt. sn 8k D0>?m ke s?m ke s.ke D
Now recompile the project and the assembl will be si"ned. 2elow is a listin" of the complete code of assembl Assembl #nfo.&b #mports S stem.1eflection #mports S stem.1untime.#nteropSer&ices <Assembl <Assembl <Assembl <Assembl <Assembl <Assembl <Assembl <Assembl > Assembl Title(DD,= > Assembl +escription(DD,= > Assembl 0ompan (DD,= > Assembl /roduct(DD,= > Assembl 0op ri"ht(DD,= > Assembl Trademark(DD,= > 0$S0ompliant(True,= > Assembl ;e File(D0>?m ke s?m ke s.ke D,=
<Assembl > 9uid(DEIFJ@AE@8BIKJ8F@KE8JFAI8LIIL00@JEAE+D,= <Assembl > Assembl Version(DL.A.MD,= The ne't step is to install the assembl into the 9lobal Assembl 0ache.
7sing 8icrosoft
This is the recommended and most common wa to add assemblies to the "lobal assembl cache. The installer pro&ides reference countin" of assemblies in the "lobal assembl cache, plus other benefits.
#n this command, assembl name is the name of the assembl to install in the "lobal assembl cache. The followin" e'ample installs an assembl with the file name m 9A0.dll into the "lobal assembl cache. "acutil 8# D0>?G/athTo2in+irector #nVS/rojectH?m 9A0.dllD After hostin" the assembl just "o to W#NNT?Assembl folder and ou will find our assembl listed there.
Now, cop the resultin" E)E in an other folder and run it. #t will displa D4ello WorldD indicatin" that it is usin" our shared assembl .
+ummary&
This article describes how to "enerate a stron" name for an assembl and to install a .dll file in the 9lobal Assembl 0ache. The 9lobal Assembl 0ache (9A0, enables ou to share assemblies across numerous applications. The 9A0 is automaticall installed with the .NET runtime. 0omponents are stored in 0>?W#NNT?Assembl .