Saturday, February 28, 2009

How to Strong Name the Enterprise Library 4.1

Introduction The Enterprise Library is a very useful tool for developing applications. The libraries provide such services as data, caching and logging. One drawback of version 4.1 compared to 3.1 is the additionally effort required to strong name the assemblies. In completing this task you could expect to spend about 4 hours preparing the dlls. It’s not difficult but seeing time is of the essence I wanted to help shorten the effort. Here’s a zip of the libraries which have been strong named [Full download - DLL Only]. You can re-compile to customize the public/private key or just download the dlls then install them in your GAC. The directory path “sn” – [strong name] holds just the dlls. Included in the directory is the GACutil.exe, SN.exe and the .pk and .snk files. Navigate to the sn directory then execute the GAC_EntLib.bat batch process. This will automatically install all the dlls in your GAC. If you only need a few of the libraries then navigate to the list.txt file to remove the unnecessary blocks. If you’d like to customize the public/private key, the process is detailed below: Steps To create a key pair 1. At a command prompt, go to the directory that will hold the key pair. 2. To create a key pair, locate the sn.exe in the sn directory then type sn –k keyfile.snk (note: keyfile is what ever name you want to give it) You must extract the public key from the key pair (the public key is required for updating the InternalsVisibleTo attribute). The following procedure describes how to extract and display the public key. To extract and display the public key 1. At the command prompt, type sn –p keyfile.snk publickey.pk to extract the public key from the key pair. 2. Type sn –tp publickey.pk to display the public key in hexadecimal. Keep the Configuration Console window open (or copy the output to a text file). Once the key is extracted then search for the InternalsVisibleTo attribute. Replace the current PublicKey with your own. Remember that the key from the extract process will be on multiple lines, so remove the line returns for one continuous string. After completing this step then recompiling the project run the BuildLibraryAndCopyAssemblies.bat in the Scripts folder. This will add the dlls to the bin directory. Copy these dlls into the sn directory then execute the GAC_EntLib.bat batch process. This will install all dlls in the GAC. You will notice the Gacutil and Sn tools are included in the project. For those missing or can’t find the exe's, I made them readily available. Reference If you’d like to conduct the manual process yourself then knock yourself out. Here’s the document to help you achieve your goal. Strong Naming the Enterprise Library Assemblies http://msdn.microsoft.com/en-us/library/dd140121.aspx

1 comment: