Tuesday, July 1, 2008

create private assembly

Assembly : The intermediate file created by different language compilers in .NET environment are called as Assembly.

The other names:

1. MSIL (Microsoft Intermediate Language)
2. CIL (Common Intermediate Language)
3. IL ( Intermediate Language)
4. Manifest (technical name of assembly)
and also called as METADATA.

Assembly is actually a single .dll or .exe file or collection of .dll files.

It is of two types: PRIVATE ASSEMBLY , GLOBAL ASSEMBLY.


Private Assembly is a .dll file created which may have collection of different .dll files created by different languages stored in hard disk. Whenever the user want to include the dll file for their own applications they can use it at runtime as a reference. It need not be publically used by all users in a system. If you want to make your assembly can be used by everyone who are all logging into the system then you have to store in the folder: c:\windows\system32\Assembly.

This can be done using .net utilities called gacutil (global assembly cache utility

Step by Step procedure to create a private Assembly:

1. Create a .vb file convert this into .dll file
2. Create a .cs file convert into .dll file.
3. Create an application which calls two dll files at runtime.
4. Combine two dll files together (vb.dll and cs.dll) and make single .dll then refer it by application (Private Assembly)

1. Creating a c1.vb file as follows:

module c1
public shared sub m1() // shared means "static " in vb.net
system.console.writeline("vb")
end sub
end module

create .dll from the source file as:

.net prompt> vbc /t:module /out:bin\c1.dll c1.vb

//create a bin folder in the current directory
// vbc is vb.net compiler /t: means what is your target file
// the target may be module (single dll), libary (coll. of dll) or exe (executable file)
// /out: means my output file stored in the name c1.dll in bin folder

2. Create the .cs file and repeat the same step

using System;
class c2
{
public static void m2()
{
Console.WriteLine("method from csharp ");
}
}

create .dll dot net prompt > csc /t:module /out:bin\c2.dll c2.cs


3. Create an application

class app
{
public static void Main()
{
System.Console.WriteLine ("this is from application");
c1.m1(); // call method from vb program c1.dll
c2.m2(); // call method from cs program c2.dll
}
}

prompt> csc /t:exe /addmodule:bin\c1.dll /addmodule:bin\c2.dll app.cs

4. Combine two .dll files together and create private assembly using assembly linker [al]

prompt> al out:bin\pa.dll /t:libary bin\c1.dll bin\c2.dll


5. Use private assembly at runtime instead of adding individual modules:

prompt> csc /t:exe /out:bin\app.exe /r: pa.dll app.cs

/r: is the reference at runtime

the single dll file named pa.dll has the reference of two dll files (hash key reference)

Hope u successfully created a private assembly and understood the concept of language integration)

No comments: