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 ...
Get C# Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.