Building and Deploying Assembly

 

  1. Open the StopWatchClassLib project in Visual Studio.NET. Open the StopWatch.cs and modify

public class StopWatch

to

public class StopWatch : System.ComponentModel.Component

  1. Open the AssemblyInfo.cs and scroll down to the bottom of the file and look for [assembly: AssemblyKeyFile("")].
  2. Modify it as follows:

[assembly:AssemblyKeyFile("..\\..\\StopWatchClassLibKey.snk")]

  1. Open a command window and cd to the StopWatchClassLib project directory. This can be easily done by following the steps below:

(a) Click on Start, Programs, Microsoft Visual Studio .NET, Visual Studio .NET Tools, Visual Studio .NET Command Prompt.

(b) In the command window type the word cd followed by a space. Do not hit return.

(c) Keep the command window on left and bring up the windows explorer on the right of the monitor.

(d) In the windows explorer, go to the director that contains this file.

(e) Drag the StopWatchClassLib directory from windows explorer to the command window.

(f) Set focus on the command window and hit return.

  1. In the command window, now type the following:

sn -k StopWatchClassLibKey.snk

  1. This generates a key pair for the application to use for Cryptography.

If you like to see the keys generated, type

sn -tp StopWatchClassLibKey.snk

  1.  This will output the key to the clipboard and you can place it any where you want by clicking on Ctrl+V. Alternately you can provide an output file name as follows:

sn -p StopWatchClassLibKey.snk key.csv

  1. Do not close the command window. We need it again for pushing the assembly to the global cache.
  2. Now compile your project in Visual Studio.NET.
  3. Using windows explorer, view the following directory:

C:\WINN\Assembly

  1. This is the global assembly cache into which our assembly will be added.
  2. In the command window, now type the following:

cd bin\debug

gacutil /i StopWatchClassLib.dll

  1. gacutil stands for the Global Assembly Cache Utility. It deploys your assembly into the global cache. Using windows explorer, verify that the global cache contains your assembly.
  2. If you  like to replace the key for an assembly, type sn –R assemblyName keyFile.snk and redeploy the assembly.