Signing an Assembly with a Strong Name
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Developer's Guide
Signing an Assembly with a Strong Name

There are two ways to sign an assembly with a strong name:

You must have a cryptographic key pair to sign an assembly with a strong name. For more information about creating a key pair, see Creating a Key Pair.

To create and sign an assembly with a strong name using the Assembly Linker

  • At the command prompt, type the following command:

    al /out:<assembly name> <module name> /keyfile:<file name>

    In this command, assembly name is the name of the assembly to sign with a strong name, module name is the name of the code module used to create the assembly, and file name is the name of the container or file that contains the key pair.

The following example signs the assembly MyAssembly.dll with a strong name using the key file sgKey.snk.

al /out:MyAssembly.dll MyModule.netmodule /keyfile:sgKey.snk

To sign an assembly with a strong name using attributes

  • In a code module, add the AssemblyKeyFileAttribute or the AssemblyKeyNameAttribute, specifying the name of the file or container that contains the key pair to use when signing the assembly with a strong name.

The following code example uses the AssemblyKeyFileAttribute with a key file called sgKey.snk.

<Assembly:AssemblyKeyFileAttribute("sgKey.snk")>
[C#]
[assembly:AssemblyKeyFileAttribute(@"..\..\sgKey.snk")]

You can also delay sign an assembly when compiling. For more information, see Delay Signing an Assembly.

When signing an assembly with a strong name, the Assembly Linker (Al.exe) looks for the key file relative to the current directory and to the output directory. When using command-line compilers, you can simply copy the key to the current directory containing your code modules.

See Also

Creating and Using Strong-Named Assemblies | Creating a Key Pair | Delay Signing an Assembly

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View