Shared Assembly
CREATE A CLASS LIBRARY PROJECT.
- Open Visual Studio 2008.
- Click on ― > File‖ ―> New ―> Project.
- Select the language as ―> Visual C# and project template as ―> Class Library.
- Enter the name as ―> SharedAssemblyLibrary.
- Click on OK. It creates a new class library project. Initially it contains a new class called class1.
- In the solution explorer, rename the class1.cs as "MyLibraryClass.cs”.
- Then type the following code.
PROGRAM FOR CLASS LIBRARY PROJECT
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SharedAssemblyLibrary { public class MyLibraryClass { public bool IsValidLogin(string Username, string Password)\ { if (Username == "system" && Password == "manager") return true; else return false; } } }
CREATE A STRONG NAME KEY.
- Right click on the project in the Solution Explorer and choose Properties.
- In the project properties, select the check box Sign the assembly
- In the Choose a strong name key file drop down, select
option. - In the Create strong name key‖ dialog box, enter the name of the strong name key file as “MyKeyFile”.
- Uncheck the ―Protect my key file with a password‖ checkbox.
- Click on OK.
CUSTOMIZE THE “ASSEMBLY INFORMATION” (ASSEMBLYINFO.CS).
Change the assembly version as “1.5.0.0”.
GENERATE THE DLL FILE.
Build the class library project by clicking on ―Build‖ menu – ―Build Solution‖.
WRITE THE ASSEMBLY INTO GAC (GLOBAL ASSEMBLY CACHE).
- Open the following folder
- C:\Windows\Assembly
- Drag and drop the “SharedAssemblyLibrary.DLL‖ file from ―bin\Debug‖ folder into the c:\windows\assembly folder.
INVOKE THE SHARED ASSEMBLY.
- Create a new Console Application. Name: SharedAssemblyDemo
- Click on Project ― Add Reference.
- Click on Browse tab
- From the class library project‘s bin\Debug‖ folder, select the “SharedAssemblyLibrary.dll file and click on OK. Then the .dll file reference will be added
PROGRAM FOR SHARED ASSEMBLIES
using System; using System.Collections.Generic; using System.Linq; using System.Text; using SharedAssemblyLibrary; namespace SharedAssemblyDemo { class Program { static void Main(string[] args) { MyLibraryClass mlc = new MyLibraryClass(); string Username, Password; Console.Write("Enter Username: "); Username = Console.ReadLine(); Console.Write("Enter Password: "); Password = Console.ReadLine(); bool result = mlc.IsValidLogin(Username, Password); if (result == true) Console.WriteLine("\nLogin successful!"); else Console.WriteLine("\nInvalid Username / Password!"); Console.Read(); } } }
No comments:
Post a Comment