Microsoft KB Archive/321917

= HOW TO: Create a Strong Named Assembly in Visual J# .NET =

Article ID: 321917

Article Last Modified on 4/26/2007

-

APPLIES TO


 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft Visual J# .NET 2003 Standard Edition
 * Microsoft .NET Framework 1.0
 * Microsoft .NET Framework 1.1

-



This article was previously published under Q321917



IN THIS TASK
SUMMARY
 * Requirements
 * Create an Assembly with a Strong Name in Visual J#

REFERENCES



SUMMARY
This step-by-step article describes how to create an assembly with a strong name in Visual J# .NET.

Assemblies can be assigned a cryptographic signature called a strong name. Strong names provide name uniqueness for the assembly and prevent someone from usurping the name of your assembly (name spoofing). If you are deploying an assembly that will be shared among many applications on the same computer, the assembly must be placed in the Global Assembly Cache (GAC). To be placed in the GAC, the assembly must have a strong name.

back to the top

Requirements
The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
 * Visual Studio .NET
 * Visual J# .NET Beta 2

NOTE: To install Visual J# .NET, see the following Microsoft Developer Network (MSDN) Web site:

Microsoft Visual J# .NET Beta 2

http://msdn.microsoft.com/visualj/jsharp/beta.asp

back to the top

Create an Assembly with a Strong Name in Visual J#
 Use the Strong Name tool (Sn.exe) that is included 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 the key pair in a file named TestKey.snk:

sn -k TestKey.snk

  Add the proper custom attribute to your Visual J# source code for the compiler to emit the assembly with a strong name. The attribute that you use depends on whether the key pair that is used for the signing is contained in a file or in a key container in 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: import System.Reflection.*; import System.Runtime.CompilerServices.*; /** @assembly AssemblyKeyFile(&quot;TestKey.snk&quot;) */ NOTE: You can add this code sample directly to your existing code module. Alternatively, in a Visual J# project, you can find the default project-generated Assemblyinfo.jsl file, which has an AssemblyKeyFileAttribute attribute with an empty-string key file name, and then fill in the key file name with the test key that you just created (TestKey.snk). 

back to the top

