how to: create an assembly with a strong name
--------------------------------------------------------------------------------
the information in this article applies to:
microsoft visual studio .net beta 2
--------------------------------------------------------------------------------
in this task
summary
prerequisites
creating an assembly with a strong name
references
summary
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.
back to the top
prerequisites
this article assumes that you have installed and are familiar with visual studio .net.
back to the top
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:
sn -k 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")]
back to the top
references
for more information about the strong name tool (sn.exe), see 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, see 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, see the c# programmer's reference.
back to the top
新闻热点
疑难解答