HOW TO: Create an Assembly with a Strong Name
2008-05-01 03:43
483 查看
ank>HOW ank>TO: ank>Create an Assembly with a Strong Name
--------------------------------------------------------------------------------
The information in this article applies ank>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 crypank>TOgraphic 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 ank>HOW ank>TO ank>Create an Assembly with a Strong Name.
back ank>TO the ank>TOp
Prerequisites
This article assumes that you have installed and are familiar with Visual Studio .NET.
back ank>TO the ank>TOp
Creating an Assembly with a Strong Name
Use the Strong Name ank>TOol (Sn.exe) that comes with the .NET Framework Software Development Kit (SDK) ank>TO generate a crypank>TOgraphic key pair.
The following command uses the Strong Name ank>TOol ank>TO generate a new key pair and sank>TOre it in a file called TestKey.snk:
sn -k Testkey.snk
Add the proper cusank>TOm attribute ank>TO your source for the compiler ank>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 Crypank>TOgraphic Service Provider (CSP). For keys that are sank>TOred in a file, use the System.Reflection.AssemblyKeyFileAttribute attribute. For keys that are sank>TOred in the CSP, use the System.Reflection.AssemblyKeyNameAttribute attribute.
The following code uses AssemblyKeyFileAttribute ank>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 ank>TO the ank>TOp
REFERENCES
For more information about the Strong Name ank>TOol (Sn.exe), see the following Microsoft .NET Framework ank>TOols Web site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cp href="http://www.66of.com" target=_blank>ank>TOols/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 ank>TO the
seover="window.status='正文--ank>HOW ank>TO: ank>Create an Assembly with a Strong Name';return true">
<Strong>
--------------------------------------------------------------------------------
The information in this article applies ank>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 crypank>TOgraphic 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 ank>HOW ank>TO ank>Create an Assembly with a Strong Name.
back ank>TO the ank>TOp
Prerequisites
This article assumes that you have installed and are familiar with Visual Studio .NET.
back ank>TO the ank>TOp
Creating an Assembly with a Strong Name
Use the Strong Name ank>TOol (Sn.exe) that comes with the .NET Framework Software Development Kit (SDK) ank>TO generate a crypank>TOgraphic key pair.
The following command uses the Strong Name ank>TOol ank>TO generate a new key pair and sank>TOre it in a file called TestKey.snk:
sn -k Testkey.snk
Add the proper cusank>TOm attribute ank>TO your source for the compiler ank>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 Crypank>TOgraphic Service Provider (CSP). For keys that are sank>TOred in a file, use the System.Reflection.AssemblyKeyFileAttribute attribute. For keys that are sank>TOred in the CSP, use the System.Reflection.AssemblyKeyNameAttribute attribute.
The following code uses AssemblyKeyFileAttribute ank>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 ank>TO the ank>TOp
REFERENCES
For more information about the Strong Name ank>TOol (Sn.exe), see the following Microsoft .NET Framework ank>TOols Web site: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cp href="http://www.66of.com" target=_blank>ank>TOols/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 ank>TO the
seover="window.status='正文--ank>HOW ank>TO: ank>Create an Assembly with a Strong Name';return true">
<Strong>
相关文章推荐
- how to sign an assembly with a strong name & how to create a pair key怎样通过强名给程序集签名以及如何创建钥匙对?
- [转]how to sign an assembly with a strong name & how to create a pair key怎样通过强名给程序集签名以及如何创建钥匙对?
- Sign Assembly with strong name
- Sign a .NET Assembly with a Strong Name Without Recompiling
- Unity错误——1.error CS1704: An assembly with the same name `UnityEngine.UI' has already been imported.
- Cannot create an NSPersistentStoreCoordinator with a nil model 问题解决
- Linux+Mono+WebService:CS1703: An assembly with the same identity--mscorlib
- 如何解决The type or namespace name 'ScriptService' could not be found (are you missing a using directive or an assembly reference?)
- The filename 未命名.ipa in the package contains an invalid character(s). The valid characters are: A-Z, a-z, 0-9, dash, period, underscore, but the name cannot start with a dash, period, or underscore
- The type or namespace name `MovieTexture' could not be found. Are you missing an assembly reference?
- How to: Create a hyperlink to view test results from an email(test manager)
- 部署强命名程序集(Strong Name Assembly)和GAC
- The type or namespace name 'log4net' could not be found (are you missing a using directive or an assembly refere
- [ZT]Three ways to tell if a .NET Assembly is Strongly Named (or has Strong Name)
- Assembly generation failed Referenced assembly ‘xxx’ does not have a strong name
- 配置c3p0-config.xml报错:Open quote is expected for attribute "name" associated with an element type "pro
- Mongodb分片问题之-please create an index that starts with the shard key before sharding
- Android App Not Install. An existing package by the same name with a conflicting signature is alread
- SAP HANA 9. SQLScript Basic 之 Create an SQLScript Procedure with Calculation Engine (CE) Functions
- Compiler Error Message: CS0234: The type or namespace name ''(are you missing an assembly reference?)