Technology with opinion

Thursday, January 26, 2006

Microsoft Enterprise Library & The Gac

For a while we have been installing a few of the assemblies from the Microsoft Enterprise Library to the GAC. The time came when I broke down and decided to install them all into the GAC.

There are many reasons to install the Enterprise Library into the GAC, they include:
  1. Component reuse, less duplicity and more consistency
  2. Performance benefits
  3. Allows use in other systems such as BizTalk
  4. Allows you to consistently manage changes throughout your organization
First step is creating strong name keys for all of the assemblies. From a command prompt (see earlier post regarding setting environmental variables):

sn -k Microsoft.Practices.EnterpriseLibrary.Data.snk

That will do the Data blocks.

Next you must modify the AssemblyInfo.cs file:

[assembly: AssemblyKeyFile("..\\..\\Microsoft.Practices.EnterpriseLibrary.Data.snk")]

Lastly you have to figure out how you want to distribute your assemblies. While you can create an installer to do it, you will need to create Installer classes to do this as you need to install them into the GAC. I think the most pragmatic approach is a batch file. You can create one batch file to install all the assemblies you choose into the GAC.

gacutil -i Microsoft.Practices.EnterpriseLibrary.Data.dll
pause
This installs the data blocks into the GAC and the pauses so that you can see the results if you want to double-click the file from Windows explorer.

In order to install all of the assemblies into the GAC you can manually do this to all of them or you can script it. I have written a small command line application that I will post later that will recursively setup assemblies to be installed into the GAC and includes all of these steps. If you do this installation manually NOTE: you do not want to install into the GAC any assemblies that end in .Design or any of the tools.

Tom Hollander has also blogged about this subject, you might want to see his comments. He is the Product Manager for Microsoft Patterns & Practices.

No comments: