.NET Assemblies Ins and Out : Part III

Previous Reading 

This article is the third part of a three-part series of articles covering the .Net assemblies. In Part 1, I covered what exactly an assembly is, and what an assembly contains. In part 2 of the series, I discussed both Private and Shared assemblies and how to create a "Shared Assembly". In part 2 I briefly mentioned some of the utilities available for working with assemblies. In this part, I will discuss in more detail than Part 2, the available utilities for manipulating assemblies.


Assembly Linker Utility


The Assembly Linker is a command-line utility named AL.exe. Ran in the form of AL sources options.


It can be used for installing shared assemblies into the Global Assembly Cache.


It can also be used to create a manifest for IL code that does not already contain one.


It can be used to add resources to an assembly.


Some interesting options that can be used with the utility are:


AL   moduleName.dll   /out: newName.exe   /main: methodName


If you have a multi-file assembly, that includes more than one Main method, you can specify to the application domain which typically contains the Main method that you want to use as the entry point for your program.


AL   moduleName.dll   /out: newName   /version: major.minor.revision.build   or   use /v:


Adds your specified version number to the manifest. You can verify your version was inserted using the ildasm.exe program.


AL   moduleName.dll   /out: newName   /win32icon: iconFileName


Adds an icon file to the assembly so that when Windows Explorer displays your app, the specified icon is shown.


Many of the fields that can be added using the AL.exe utility such as Company, copyright, etcetera, can be viewed using the Assembly Cache Viewer/properties.


Strong Name Utility


The Strong Name utility is a command-line utility named Sn.exe. Ran in the form of Sn sources options.


It can be used to create strong names or shared names for assemblies.


It can be used to create public/private key pairs.


Some useful options that can be used with the utility are.....  


Sn   -k   keyFile.snk


This is the same command that we used in Part 2 to create a set of keys.


Sn   -R   assemblyName keyFile.snk


Re-signs a previously signed assembly.


Sn   -v   hello.dll


This verifies that the assembly is a strong-named assembly.


Assembly 'hello.dll' is valid


Assembly Cache Viewer

The Assembly Cache Viewer is a Windows Shell extension named Shfusion.dll .

This extension is integrated into Windows Explorer when the SDK is installed so that you may view assemblies in the Assembly Cache.


It can be used to view properties of assemblies, add assemblies to the cache or even remove assemblies from the cache.

Use Explorer to navigate to your assembly directory: C:\Windows\assembly. Right-click on an assembly, and select properties. You will see properties such as version, name trademark, copyright, and others. This method can also be a quick way to verify that fields you set using the Assembly Linker utility are as you expected.

To delete an assembly from the cache, right-click on the assembly and select Delete.


To add an assembly to the assembly cache, drag and drop the assembly (that must be a shared name assembly) into the Cache.


NOTE: Adding an assembly this way does not perform the install as does the AL.exe utility. I used the preceding method to copy and delete assemblies from the cache and it did not create or remove the parent folders of the shared assembly.


Global Assembly Cache Utility

The Global Assembly Cache Utility performs the same operations on assemblies as the Windows shell extension rescribed above. The Global Assembly Cache Utility is the command line version and is included with the SDK as a file named Gacutil.exe.

Syntax and usage are as follows:


Gacutil   -l


The -l (ell, not number one) option will report the number of shared assemblies in the global cache and will list each shared assembly along with its version and strong name.


Gacutil   -i assemblyName


This installs the assembly to the global cache and does create the needed directories just as the AL.exe utility did when we installed the assembly in PART 2 of the series.


I tried using the -u option to remove my assembly but this option did not properly work. The Gacutil   -u assemblyName, ver=versionNum command ran and said that it successfully removed my assembly, but when I viewed the cache the assembly and its parent folders were still there.


Microsoft Intermediate Language Disassembler


The IL Disassembler is a utility named ildasm.exe.


It can be used for viewing the internals of an assembly and can also generate a text file that can be edited and then recompiled using the Microsoft Intermediate Language Assembler (ilasm.exe).  




This produces a dialog box that allows you to navigate the assemblies internals. The following is a list of the symbols used to identify the parts of your assembly.


ildasm   /TEXT


This causes the ildasm output to be displayed in a console window instead of the dialog box.   


ildasm   /OUT=fileName


This causes the ildasm output to be saved to the specified file instead of the dialog box.


There are many other utilities provided with the SDK. For a list of available utilities visit Framework Tools.