Monday, May 23, 2011

How to create shared assemblies in Aspnet

Hi friends, in this article I would like to explain creation of shared assembly.
Let’s start with, what is an assembly..?
In simple, Assembly is unit of deployment like EXE or a DLL.it contains one or more files like dll,exe’s,html files etc…,

Now come to the main point what is an shared assembly..?
Overview:
-->All the predefined assemblies are shared assemblies

-->Shared assemblies need to be registered with GAC (Global Assembly Cache)

-->C:\Windows\Assembly folder is called as GAC

-->A DLL which is registered with GAC is called as Shared Assembly

-->A DLL which contains strong name can be registered as shared assembly

-->Strong name provides unique identifier to the assembly which is also called as public key token

-->Syntax to create strong name:

sn –k filename.snk

-->A DLL with strong name can be registered as shared assembly with the help of gacutil tool


Syntax:

                gacutil –I dllfilename

Simple steps to create a shared assembly

First open the visual studio 2005

Next select the class library project and change the name as firstsharedprogram.

Next,write the below code
Using System.Data;

Using system.Data.sqlclient;


Namespace firstsharedprogram

{

 Public class check

{

Public static Datatable GetData(String connectionstring,string tabelname)

{

String query=”select * from” +tablename;

Sqlconnection con=new sqlconnection (connectionstring);

SqlDataAdapter da=new sqlDataAdapter(query,con);

Dataset ds=new Dataset ();

da.fill(ds,”newtablename”);

Datatable dt=new Datatable[“newtablename”];

Return dt;

}//close get data

}//Test Class

}//Close namespace

Next,save the file and minimize it


Next we have to create a strong name

For this,open the .Net command prompt and type the following code

C :> cd D:\Firstapplication\ firstsharedprogram\bin\debug


D:\Firstapplication\ firstsharedprogram\bin\debug > sn –k xyz.snk

Next,we have to integrate the xyz.snk with our project that is   firstsharedprogram


For this, open the project and click on the firstsharedprogram properties,

Next click on the signing next click on the checkbox of “sign the assembly”

Next select the Browse from combo box then choose xyz.snk

Next,Build the project

For this open the .Net command project
D:\Firstapplication\ firstsharedprogram\bin\debuggacutil –I firstsharedprogram.dll

Ok..its over we are succesfully created the shared assembly

Now firstsharedprogram.dll is registered in with GAC.so now we can use this assembly with any assembly


That’s it…..Friends
developercode
About the Author
Sayyad is a Software Engineer, Blogger and Founder of Developers Code from India.His articles mainly focus on .Net (Web and Windows based applications), Mobile Technologies (Android,IPhone,BlackBerry) and SEO.

Labels: , , ,

6 Comments:

At March 14, 2011 at 11:59 PM , Anonymous Anonymous said...

This is not an appropriate font for an article with code...

 
At March 15, 2011 at 8:26 AM , Blogger Developers Code said...

Thanks for sharing..i changed the font,i think its look better..

 
At June 7, 2011 at 8:13 AM , Anonymous Anonymous said...

Nice explanation...Good

 
At June 28, 2011 at 9:50 AM , Anonymous jodha said...

Thanks for sharing

 
At June 28, 2011 at 9:51 AM , Anonymous Tanisha said...

Welcome

 
At June 28, 2011 at 10:17 AM , Anonymous Anonymous said...

Nice explanation...Good

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home