Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 302340 - Last Review: March 29, 2007 - Revision: 3.3
How To Create an Assembly with a Strong Name in .NET Framework SDK
This article was previously published under Q302340
Assemblies can be assigned a cryptographic signature called
a strong name, which provides name uniqueness for the assembly and prevents
someone from taking over the name of your assembly (name spoofing). If you are
deploying an assembly that will be shared among many applications on the same
computer, it must have a strong name. This document describes how to create an
assembly with a strong name.
Prerequisites
This article assumes that you have installed and are familiar
with Visual Studio .NET.
Creating an Assembly with a Strong Name
- Use the Strong Name tool (Sn.exe) that comes with the .NET
Framework Software Development Kit (SDK) to generate a cryptographic key
pair.
The following command uses the Strong Name tool to generate a
new key pair and store it in a file called TestKey.snk: - Add the proper custom attribute to your source for the
compiler to emit the assembly with a strong name. Which attribute you use
depends on whether the key pair that is used for the signing is contained in a
file or in a key container within the Cryptographic Service Provider (CSP). For
keys that are stored in a file, use the System.Reflection.AssemblyKeyFileAttribute attribute. For keys that are stored in the CSP, use the System.Reflection.AssemblyKeyNameAttribute attribute.
The following code uses AssemblyKeyFileAttribute to specify the name of the file that contains the key
pair.
NOTE: In Microsoft Visual Basic, the assembly level attributes must
appear as the first statements in the file.Visual Basic .NET Code
Imports System
Imports System.Reflection
<assembly:AssemblyKeyFileAttribute("TestKey.snk")>
C# Code
using System;
using System.Reflection;
[assembly:AssemblyKeyFileAttribute("TestKey.snk")]
For more information about the Strong Name tool (Sn.exe),
see the following Microsoft .NET Framework Tools Web site:
For more information about the .NET Framework SDK, see the
following Microsoft Web site:
For more information about global attributes, see the C#
Programmer's Reference.
APPLIES TO
- Microsoft .NET Framework 1.0
- Microsoft .NET Framework 1.1
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate