How to:create an Assembly with a strong Name

Source: Internet
Author: User
Tags reflection visual studio
How to:create an Assembly with a strong Name

--------------------------------------------------------------------------------
The information in this article applies to:

Microsoft Visual Studio. NET Beta 2

--------------------------------------------------------------------------------

In the This TASK
SUMMARY
Prerequisites
Creating a Assembly with a strong Name
REFERENCES


SUMMARY
Assemblies can is 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 a assembly that'll be shared among many applications on the same computer, it must have a strong n Ame. This document describes how to create the assembly with a strong name.

Back to the top

Prerequisites
This article assumes to have installed and are with Visual Studio. NET.

Back to the top
Creating a Assembly with a strong Name
Use the strong Name tool (Sn.exe) This comes with the. NET Framework Software Development kits (SDK) to generate a cryptogr Aphic 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:


Sn-k testkey.snk
Add the proper custom to your source for the compiler to emit the assembly with a strong name. Which attribute you to use depends on whether the key pair this is used for the signing is contained in a file or in a key co Ntainer within the cryptographic Service Provider (CSP). For the keys that are stored in a file and use the System.Reflection.AssemblyKeyFileAttribute attribute. For the keys this 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 the "the" 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")]
Back to the top
REFERENCES
For more information about the strong Name tool (Sn.exe), and the following Microsoft. NET Framework Tools Web site:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpgrfstrongnameutilitysnexe.asp
For more information about the. NET Framework SDK, the following Microsoft Web site:
Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/nfstart/html/sdkstart.asp
For more information about global attributes, the C # Programmer ' s Reference.

Back to the top

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.