Creating a Strong Name


You create a shared assembly by generating a strong name. To accomplish this, follow these steps:

  1. Use the sn.exe utility located in C:\Program Files\Microsoft Visual Studio .NET 2003.0\SDK\v1.1\Bin. Select sn.exe to place it in the Command window. This utility creates a .snk file. Several flags are provided to generate the strong name. If you select the -k flag, it will look like this:

      sn -k Registration.snk
  2. The template syntax is <filename>.snk. Provide an appropriate name that identifies your class.

  3. Select <initial directory> and specify where you want to store your strong name. You will see the strong name being generated. Also, place it in your project directory for easy access.

  4. Select OK and you will see your strong name listed on the Tools menu.

Once you have created the strong name, the Framework provides a tool called gacutil.exe, located in the same directory as sn.exe. Type the following from the Visual Studio Command window: gacutil /i MyIFCEAssembly.dll to place it in the GlobalAccessCache (GAC). You can use an alternate method by dragging the assembly key to the GAC located in C:\Windows\Assembly. Once you are there, select Properties, and the Strong Name field displays as True.

If your strong name does not appear automatically in the Solutions Explorer window, check to ensure that it has actually been created. If the strong name property displays as False, try selecting AssemblyInfo.cs, and opening the dialog box to see if the following information is present in the assembly:

<Assembly: AssemblyTitle("")>
<Assembly: AssemblyDescription("")>
<Assembly: AssemblyCompany("")>
<Assembly: AssemblyProduct("")><Assembly: AssemblyCopyright("")>
<Assembly: AssemblyTradeMark("")>
<Assembly: CLSCompliant(True)>
...
Version information for an assembly consists of the following:
' Major Version
' Minor Version
' Build Number Revision
' Revision
'You can specify all the values or you can default the Build
'by using the '*' as shown below+
,Assembly: Assembly Version("1.0">
If you don’t see the Assembly key, follow these instructions:
Copy <Assembly: AssemblyVersion("1.0.*")
Add the following code:
<Assembly: AssemblyKeyFile ("..\\..\\MyIFCEAssembly.snk")

Recompile the assembly and check the MyIFCEAssembly property. Then, drag the assembly to the GAC. Voila! Now the assembly is global and can be shared by other applications. It was just that easy to make your assembly public.




.NET & J2EE Interoperability
Microsoft .NET and J2EE Interoperability Toolkit (Pro-Developer)
ISBN: 0735619220
EAN: 2147483647
Year: 2004
Pages: 101
Authors: Simon Guest

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net