What is Assembly
Assembly is a basic building block of .Net framework
application. It is basically a compiled code which can be executed by CLR. An
assembly is a collection of types and resources that are built to work together
and form logical unit of functionality. Assembly can be a DLL or exe depending
upon the project which we chose.
Assemblies are basically of two types:-
- Private Assembly
- Shared Assembly
Private Assembly
It
is an assembly which is being used by a single application only. Suppose we
have a project in which we refer a dll so when we build that project that dll
will copied into the bin folder of our project. That dll becomes private
assembly within our project. Generally the dlls which are meant for a specific
project are used as private assemblies.
Shared Assembly
Assemblies which can be used in
more than one project are known to be shared assembly. Shared assemblies are
generally installed in GAC.
Assemblies which are installed in GAC are made available to all the dot net
applications on that machine.
However there are two more types of
assemblies in dot net that are Satellite Assembly and Shared Assembly.
GAC
GAC stands for Global Assembly
Cache. It is a memory which is used to store the assemblies which are meant to
be used by various applications. Every computer which has CLR installed must
have GAC. GAC is a location which can be seen at the path below :-
“C:\Windows\assembly”
for .net applications with framework upto 3.5. For higher frameworks like 4,4.5 GAC can be seen at “C:\Windows\Microsoft.NET\assembly\GAC_MSIL”.
“C:\Windows\assembly”
for .net applications with framework upto 3.5. For higher frameworks like 4,4.5 GAC can be seen at “C:\Windows\Microsoft.NET\assembly\GAC_MSIL”.
How to Install assembly in GAC ?
In class library project I have created a Class Student that contains a method which returns a string. Now I will add reference of class library in my Console application project and will use this method. After Building the project you will see that ClassLibrary DLL is present there(It will come when we build our project). This DLL is a Private Assembly now.
Generating Strong Name
To make our assembly strongly named we need to generate a unique key value pair, for that we need to open the visual studio command prompt. We can open that by going through all programs -> Visual Studio 2012(Any version which you have) -> Visual Studio Tools -> Developer Command Prompt for VS and open that as run as administrator.
Then type the command sn –k “Path
where you want that key will get generated”
This will generate the unique key pair which we will use in our application. Now move to visual studio Class library Project and open AssemblyInfo.cs file which is residing in the Properties folder of your project. In the bottom of that file add a new attribute which refer to the key pair file which we have just created.
Now to install assembly in cache type the following command
in the command prom
gacutil
–i “Name of the Class library”
No comments:
Post a Comment