ஊத்துக்குளி வெண்ணெயிடாடோய்

Sunday, October 25, 2009

HOWTO: Strongly name prebuilt assemblies

When you're building assemblies, it's not hard to apply a strong name to them.
1. Create a strong name assembly key file

From a VS.NET command prompt, use the SN.EXE utility to create a file containing the public key/private key pair:c:\>sn -k c:\keypair001.snk
2. Add reference to the assembly key file to your assembly project

Open the AssemblyInfo.cs file in your project and add the following attribute:[assembly: AssemblyKeyFile(@"c:\keypair001.snk")]
3. Compile your assemblySame way you would any other day of the week.
4. Obtain the public key to your key file

You may need this in the future. After you build your assembly, from a VS.NET command prompt, use the SN.EXE utility again to get the public key of your key pair:c:\>sn -T yourAssembly.dll
5. Obtain the public key blob to your key file

You'll need this in CAS policy files... it's the hex public key blob... use the SECUTIL.EXE utility:c:\>secutil -hex -s yourAssembly.dll


However, what if you need to apply a strong name to an assembly that was provided, already compiled, to you and you don't have the source? You first will need to produce the Microsoft intermediate language (MSIL) for the assembly using the ILDASM.EXE utility, then use an assembly key file to sign that MSIL into a new DLL using the ILASM.EXE utility.
1. Obtain the MSIL for the provided assembly

From a VS.NET command prompt, enter the following:c:\>ildasm providedAssembly.dll /out:providedAssembly.il
2. Rename/move the original assembly

I just tack on ".orig" to the filename.

3.Create a new assembly from the MSIL output and your assembly keyfile

Assuming you already have an assembly key pair file (if not, see #1 in previous steps), do the following from a VS.NET command prompt:c:\>ilasm providedAssembly.il /dll /key=keypair001.snk

Rate this post at www.thamizmanam.com Current rating is: Click on the stars for voting pad.

1 Comments:

Post a Comment

<< Home