only for RuBoard - do not distribute or recompile Previous Section Next Section

E.1 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 snutility) and install it into the global cache (using the gacutil utility).

E.1.1 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

E.1.2 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.netmodule b.netmodule

E.1.3 Building with Your New Assemblies

You can now create applications with the new assembly by referencing it on the compiler command line. For 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.

E.1.4 Sharing Assemblies

To share assemblies across multiple applications where the assembly itself doesn't reside in the same directory, you need to install it into the assembly cache. To install an assembly into the cache, it must be signed with a strong name. The sequence is:

  1. You must generate a key file. For example:

    sn -k key.snk
  2. Then build an assembly that is signed with the strong name:

    al /out:e.dll /keyfile:key.snk a.netmodule b.netmodule
  3. Once your assembly is signed, you can install it in the global assembly cache.

Note that installing an assembly to the shared cache doesn't copy it to anywhere, so when specifying the reference on compilations, you need to specify the assembly file location for the compiler:

csc /r:..\e.dll f.cs
only for RuBoard - do not distribute or recompile Previous Section Next Section