Showing posts with label gac. Show all posts
Showing posts with label gac. Show all posts

Friday, December 12, 2008

Source Assembly

Assemblies:

• Collection of .dll/ .exe files are called as Assembly.
• Collection of class modules as a single .DLL file.

Module: A single .dll / .exe file

Library: Collection of dll files

Assemblies are loaded on demand.
Types: Private and Global Assembly

Just a Small discussion on Why Assemblies???????
if the programming logic is splitted into different logical units say dll's
and developed in different programming languages vb.net,c#.net,vj#.net,....

you are in need to develop an application which simple want to access many dll's at runtime.
Then every dll you have to refer at runtime. Instead if we first group the necessary dll's that we want
it is easy for us to just refer that single dll file. This process is called as Assembly creation.

PRIVATE ASSEMBLY
Location is specified at compile time and probably in current directory
Identified by name and version


GLOBAL ASSEMBLY
Location is specified at compile time and in GAC. C:/windows/assembly
Identified by globally unique name and version


// some of the command line options while creating assemblies
//*************************************************************
/* /t:module -----> target: is a module file (may be a single dll file)
/t:library -----> target: is a library file (collection of dll files)

/t:exe -----> target: is a executable file

/out:bin\pa.dll --> output: file name pa.dll created in bin directory

/r:bin\pa.dll --> reference: at run time pa.dll used as reference
al --> Assembly Linker

*/////////////////////////////////////////////////////////////////////////


TO DEMONSTRATE THE ASSEMBLY CONCEPT WE ARE TRYING TO CREATE THE FOLLOWING FILES AND
THE STEPS IN BRIEF:

1. Create a class1.vb file (vb.net file)
2. Create a class2.cs file (csharp file)
3. Compile class1.vb and create class1.dll
4. Compile class2.cs and create class2.dll
5. combine class1.dll,class2.dll and create pa.dll using utility al (private assembly)
6. create an application program app.cs (csharp file)
where we are calling

class1.method1
class2.method2

7. Test your app.cs and at runtime use pa.dll as reference



steps in detail: (create a directory in c:\windows\temp\) example==> asm.
***************

1. create a class1.vb file

Public Class class1
Public Shared Sub m1() ////////////////shared means static in vb.net
System.Console.WriteLine("vbmethod")
End Sub
End Class

2. create a class2.cs file

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

3. Compile class1.vb and get class1.dll as follows:

******* CREATE A BIN DIRECTORY IN C:\WINDOWS\TEMP\ASM ***********


c:\windows\temp\asm> vbc /t:module /out:bin\class1.dll class1.vb


4. Compile class2.cs and get class2.dll as follows:

c:\windows\temp\asm> csc /t:module /out:bin\class2.dll class2.cs


5. Combile two dll files and create a private assembly named pa.dll

c:\windows\temp\asm> al /t:library /out:bin\pa.dll bin\class1.dll bin\class2.dll


6. Create an application to access your private assembly (app.cs)

class test
{
public static void Main()
{
System.Console.WriteLine("Application Main");
class1.m1(); //static members can be directly accessed by class name
class2.m2(); //.....................................................
}
}


7. To compile your app.cs use pa.dll as your reference

c:\windows\temp\asm>csc /t:exe bin\pa.dll /out:bin\app.exe app.cs

8. Now your app.exe is ready in bin directory

9. you can run simply typing app at

c:\windows\temp\asm\bin> app

10. thus we have created a private assembly successfully and accessed.




Suppose if you didnt create an assembly then you have to do the following:::
>>>>>>> csc /t:exe /out:bin\app.exe /addmodule:bin\class1.dll /addmodule:bin\class2.dll app.cs

Here, you have to add all the modules individually .. which is not advisable if u have huge dll's to refer.