C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Creating a Shared Assembly


Posted Date: 28 Jun 2007    Resource Type: Articles    Category: .NET Framework

Posted By: Gomathi NS       Member Level: Silver
Rating:     Points: 10



Introduction


Assembly is a unit of deployment like EXE or dll. There are 3 types of assembly available in .NET.
They are,
1. Private Assembly
2. Public/Shared Assembly
3. Satellite Assembly

Private Assemblies are created and stored in the Application's directory.

Public/Shared assemblies are used by one or more applications and stored in the Global Assembly Cache. Usually they are libraries of code.

Satellite Assemblies are assemblies which are customized for localization in multilingual applications.

Here are the steps you need to make a Public/Shared assembly.

<h3><U>STEP 1:</U>(Create a Strong Name)</h3>
Create the strong Name for your dll using the following command.
In the .NET Framework SDK Command Prompt,
 <Drive>:/Program Files/Microsoft Visual Studio 8/SDK/v2.0> sn -k myStrongName.snk 


<h3><U>STEP 2:</U> (Create a Class)</h3>
In the Command Prompt,
 <Drive>:/Program Files/Microsoft Visual Studio 8/SDK/v2.0> notepad myClass.cs


Type the following program and save.
 
using System;
using System.Reflection;

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyKeyFile("myStrongName.snk")]

public class clsDotNetSpider
{
public int Add(int a, int b)
{
return(a + b);
}
}

<h3><U>STEP 3:</U>(Make the Assembly)</h3>
This will create the Assembly of your class "myClass.cs"
 <Drive>:/Program Files/Microsoft Visual Studio 8/SDK/v2.0> csc -t:library myClass.cs


<h3><U>STEP 4:</U> (Making it as PublicAssembly)</h3>
The following command will install your dll in Global Assembly Cache-GAC(<Drive>:/WINDOWS/ASSEMBLY)
 <Drive>:/Program Files/Microsoft Visual Studio 8/SDK/v2.0> gacutil /i myClass.dll


<h3><U>STEP 5: </U>(Using your PublicAssembly)</h3>
1. Copy and paste the myClass.dll into
<Drive>:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies
folder.

2. Create a new ConsoleApplication.

3. Click --> Add reference. Choose myClass from the .Net Components List.

4. Now you can use the myClass.dll in your application
 
using System;

namespace GACSample
{
class Program
{
static void Main(string[] args)
{
clsDotNetSpider obj = new clsDotNetSpider();
int Result = obj.Add(2, 3);
Console.WriteLine(Result);
Console.ReadKey();
}
}
}


Summary


Shared assemblies are stored in the GAC. This is a system-wide cache and all applications on the machine can use any assembly in the GAC. To an application user it appears that the GAC is a single folder, however, it is actually implemented using FAT32 or NTFS nested folders which means that there can be multiple versions (or cultures) of the same.




Responses

Author: Gomathi NS    30 Jun 2007Member Level: Silver   Points : 0
Please Feel Free to send your Feedback


Author: Mydeen    30 Jun 2007Member Level: Bronze   Points : 0
Good Article. Very useful for beginners..

Mydeen S
Take solutions
India



Author: Khemchandra Gupta    04 Jul 2007Member Level: Silver   Points : 0
Very good for those are starting
your step by step method is very good
thanks


Author: Ipsita Routray    11 Jan 2008Member Level: Bronze   Points : 0
This article is very good. But i have little concern.While i was working in the command prompt, i got an error that source file could not be found after the command: csc -t:library myClass.cs.

I saved this file in C drive.Please anybody can help me out regarding this.


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Shared assembly  .  Dot net  .  Create  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Function overloading, Operator overloading in Ironpython
Previous Resource: Confidence development through Ado.net
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use