Skip to navigation

PCPro-Computing in the Real World Printed from www.pcpro.co.uk

Register to receive our regular email newsletter at http://www.pcpro.co.uk/registration.

The newsletter contains links to our latest PC news, product reviews, features and how-to guides, plus special offers and competitions.

Real World Computing

Assembling assemblies

Posted on 17 Jan 2006 at 16:25

Thomas Lee looks at what .NET assemblies are made up from and shows you how to make them

There are broadly speaking two types of assembly: process assemblies and library assemblies. A process assembly, typically containing EXE files, represents a process that will use classes defined in library assemblies. Unlike Win32, .NET does not employ the filename extension to determine whether the file is a process or library, which means a library may have either a DLL or an EXE extension.

An assembly can be made up of one or more files, which may include multiple code files and a separate manifest. For example, an assembly might contain some executable code plus some resources such as JPEG and BMP image files. Since you can use different languages to create individual code modules under .NET, you could in theory combine several separately compiled code modules to create just one assembly, but in practice this doesn't happen, because Visual Studio only allows you to create an assembly made up of a single code module. If you build a .NET app, such as a console application or Windows app, you must have at least one assembly: your application. Your app may have functionality contained in separate DLLs - for performance reasons, to simplify development or for localisation - and in such cases you may have multiple assemblies to manage.

While I haven't talked about ASP.NET in much detail yet, assemblies are also used there. In the case of ASP.NET, you'll typically have an assembly for each page of your ASP.NET website, plus additional assemblies that perform common logic to be shared among the rest of the pages.

There are two tools you can use to look inside an assembly and view its contents, and it would be good idea to get both of them and start looking inside some assemblies to get acquainted. The first tool is Microsoft's Intermediate Language Dis-assembler, or ILDASM, contained in the .NET Software Development Kit (SDK), which you can download from msdn.microsoft.com. The second program is Reflector, a class browser for .NET components, which you can use to browse and search an assembly's metadata, IL instructions, resources and XML documentation. Written by Lutz Roeder, Reflector is a free download. For more information about the tool and to download a copy, see www.aisto.com

Building Assemblies

Building an assembly is generally done with one of the .NET language compilers, and to illustrate the concept of assemblies and how they work I've created two simple C# programs. The first is called Client (client.exe), which makes use of an external DLL to perform a calculation and print the results. Here's the source code for the client program:

using System;

public class Client

{

public static void Main()

{

Console.WriteLine("In Client.exe");

Maths m = new Maths();

long r1 = 2;

long r2 = 2;

long r = m.Add(r1, r2);

Console.WriteLine ("{0} + {1} = {2}", r1, r2, r);

}

}

The second component, maths.dll, implements the external Maths library use by client.exe, and its source looks like this.

using System;

public class Maths

{

public long Add(long a, long b)

{

Console.WriteLine("In Maths.dll");

return a + b;

}

}

To build these two components, let's use the built-in C# Compiler (of course, to do this you must first have the .NET Framework loaded). Once you've created the two source files client.cs and maths.cs, you compile them from the command line as follows:

1 2 3 4 5
Be the first to comment this article

You need to Login or Register to comment.

(optional)

advertisement

Latest Real World Computing
Latest Blog Posts Subscribe to our RSS Feeds
Latest News Stories Subscribe to our RSS Feeds
Latest Reviews Subscribe to our RSS Feeds

advertisement

Sponsored Links
 
SEARCH
SIGN UP

Your email:

Your password:

remember me

advertisement


Hitwise Top 10 Website 2008