Register an Assembly in the GAC using sn.exe tool

HOWTO: Register an Assembly in the GAC

Learn how to register an assembly in the GAC.

1) Create an assembly key file

Use the sn.exe tool to create a key file:
sn -k StrongNameFile.snk

If your path environment variables aren't set, you'll have to go to the C:\Program Files\Microsoft.NET\FrameworkSDK\Bin\ directory to run sn.exe)
The filename "StrongNameFile.snk" can be any name you want.

2) Edit your assembly
Now you have to add a tag which will link your assembly key to the assembly:

using System.Reflection;

Normally this is done in the utility AssemblyInfo.cs (vb) file.

3)Add your assembly to the GAC

gacutil /i AssemblyFileName.dll

To uninstall this assembly from the GAC, use the command:

gacutil /u AssemblyFileName

4) (Opional) Add your assembly to machine.config

Locate the <assemblies> tag (for web apps,under <configuration>/<system.web>/<compilation>/<compilers>/<assemblies>)
Between the <assemblies> tags, enter:

<add assembly="AssemblyFileName, Version=, Culture=neutral, PublicKeyToken=5edf592a9c40680c" />

You can get the information for the assembly attribute, by running the gacutil /l command which will return a list of all the assemblies in the GAC. You will have to look for the one you just added and copy the entire line (less the Custom=XXX part at the end).

At this point, you will be able to place this directive in your aspx pages.

<%@Import Namespace="YourNamespace"%>

or, you can set a reference in the Visual Studio IDE as you would with other GAC Assemblies.

Submission Date:  9/23/2005 3:16:40 PM
Submitted By:  Peter Bromberg
My Home Page:

By Peter Bromberg   Popularity  (3013 Views)