O'Reilly logo

C# Essentials by Peter Drayton, Ben Albahari, Brad Merrill

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix E. Working with Assemblies

This appendix describes a number of useful techniques for working with assemblies. Among the topics covered are how to create modules, how to manage the global assembly cache, how to make assemblies shareable, and how to use the nmake utility to automate your builds.

Building Shareable Assemblies

For most applications you build components that are either standalone assembly EXEs or DLLs. If you want to build shareable components that are shared across multiple applications, you need to give your assembly a strong name (using the sn utility) and install it into the shared assembly (using the al utility).

Building Modules

The al utility doesn’t rebuild assemblies from other assemblies, so you need to compile your C# files as modules, using the flag (/target:module). Here’s an example:

csc /target:module a.cs

Linking Modules to Assemblies

Once your modules are built, you can create a single shared assembly with the al (alink) utility. You specify the name of the new assembly and the source modules. Here’s an example:

al /out:c.dll a.dll b.dll

Building with Your New Assemblies

You can now create applications with the new assembly by referencing it on the compiler command line. Example:

csc /r:c.dll d.cs

Note that in order to use classes within the namespaces contained in the c.dll assembly of the preceding example, you need to specify the using keyword to reference the namespace.

Sharing Assemblies

To share assemblies across multiple applications where the assembly ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required