assemblies

25
Assemblies in .Net 1

Upload: janas-khan

Post on 14-Dec-2014

1.167 views

Category:

Technology


3 download

DESCRIPTION

A Great Presentation of Assemblies in .NET Technology.

TRANSCRIPT

Page 1: Assemblies

1

Assemblies in .Net

Page 2: Assemblies

2

What is an Assembly

• When create a project in Visual Studio .Net and compile it, assemblies are created.

- .DLL- .EXE

• These assemblies are the fundamental units of applications in the .NET Framework.

• An assembly contains one or more compiled classes.

Page 3: Assemblies

3

• When compile a program, the compiler translates the source code into the Intermediate Language code (IL).

• In addition to translating the code into IL, the compiler also produces metadata about the program during the process of the compilation.

• The IL and the metadata are linked in an assembly.• An IL and metadata exist in portable executable

file(EXE/DLL).

Page 4: Assemblies

4

• In any Project folder, In bin folder that contains, say myproject.dll/ myproject.exe and myproject.pdb files.

• The myproject.dll/ myproject.exe is the assembly, and myproject.pdb ( program database ) file contains debugging information for the assembly.

Page 5: Assemblies

5

Structure of Assemblies

• An assembly also contains an assembly manifest that contains the assembly metadata.

• This metadata contains information about the classes, methods and properties and so on

• This information is stored within the assembly file (DLL/EXE) itself.

• Resources are non executable data that is a part of Application.

e.g: images, sound and video etc.

Page 6: Assemblies

6

Process assemblies (EXE) and library assemblies (DLL)

• A process assembly represents a process which uses classes defined in library assemblies

Page 7: Assemblies

7

Feature of Assemblies

• Assemblies are self describing• Assembly can be load side by side• Assembly can be private or shared

Page 8: Assemblies

8

Why use Assemblies?

• The goal of the assembly model is the elimination of DLL Hell. Under the current model.

• A catalog of DLLs is centralized in the Windows Registry.

• When a new version of a DLL is published, the registry re-references the catalog to point to the new DLL.

Page 9: Assemblies

9

Types of Assemblies

• Assemblies can be private or shared.• The assembly which is used by a single

application is called as private assembly.• Suppose we have created a DLL which

encapsulates business logic. This DLL is used by the client application only and not by any other application.

Page 10: Assemblies

10

Shared assemblies

• Suppose we are creating a general purpose DLL which provides functionality to be used by a variety of applications. Now, instead of each client application having its own copy of DLL we can place the DLL in 'global assembly cache'. Such assemblies are called as shared assemblies.

Page 11: Assemblies

11

Benefits of Private Assemblies

• Private assemblies are installed in a directory named bin located under the application directory. These files are private to the application.

• It is great for small utility Assemblies/ application specific code

Page 12: Assemblies

12

Disadvantages:

• When you have multiple applications using one assembly, you have to deploy the assembly to the bin directory of each application.

Page 13: Assemblies

13

How to create an Assembly

• A shared assembly can be created in Visual Studio.Net by a Pair of tool.

- SN.exe utility.- Gacutil tool

• The sn.exe utility is located in the Bin directory. • After creating the shared assembly we should sign

the shared assembly to the GAC by using Gacutil tool.

Page 14: Assemblies

14

Calculator.cs

namespace calculate{ public class mathoperation {

public int subtraction(int a, int b) {return a-b; }

}

}

c:\>csc /t:library Calculator.cs

Created DLL file “Calculator.dll”

MathProgram.cs

using System;using calculate;

class mycalc{

static void Main(){mathoperation c1 = new mathoperation();int result = c1.subtraction(50,20);Console.WriteLine("The result is:{0}",result);Console.Read();}

}

c:\>csc /t: /r:Calculator.dll MathProgram.cs

Created EXE file “MathProgram.exe”

Page 15: Assemblies

15

What is Global Assembly Cache?

• An assembly that is shared by multiple applications is called a global assembly and is installed in the global assembly cache (GAC).

• Global assembly cache is nothing but a special disk folder where all the shared assemblies are kept.

• It is located under <drive>:\Windows\Assembly folder on every machine running the .NET framework.

Page 16: Assemblies

16

Add an External Tool

• Visual Studio provides the functionality to include external tools in the Tools menu.

• To modify the existing tools or to add new tools of your own, you simply need to go to Tools → External Tools.

Page 17: Assemblies

17

What is ILDASM ?

• It is Intermediate Language Dissembler SDK Tool that is used to examine MSIL code and the parts of the Assembly.

• It comes with the installation of Visual Studio IDE.

Page 18: Assemblies

18

How to Add an External Tool

Page 19: Assemblies

19

Click on add button and spedify name ILDASM.

Page 20: Assemblies

20

Page 21: Assemblies

21

View the content of an AssemblyClick on File menu and Then Open a File

Page 22: Assemblies

22

Select an Assembly File and Open

Page 23: Assemblies

23

Double Click on Manifest

Page 24: Assemblies

24

Double Click on mycalc

Page 25: Assemblies

25

• End of Presentation.• Thank’s for Watching.

JANAS KHAN