Sunday, January 2, 2011

Creating Shared Assembly

To create a shared assembly following steps are required-
Step1 Create a strong name file.
           sn -k strongNameFile.snk
          
A strong name file will created in the  d:\a1dotnetguru\ directory.



Step2 Sign your assembly by that strong name.
           using System;
           using System.Reflection;
          [assembly:AssemblyKeyFile("strongNameFile.snk")]
          namespace myproject
         {
            public class employee
          {
            public string work()
           {
              return "doing work";
          }
   
       }
    }


          Note: Now this assembly will have public key.
Step3 Compile the code into DLL.
          csc /t:library example1.cs

Step4 Register it in GAC
          Gacutil /i example1.dll


2 comments:

  1. Summary of above:
    1. Create a strong name file. (StrongFileName.snk)
    2. Create a source file that include Strong name file.
    3. Create dll from the source file.
    4. Mapped or register dll in the assembly cache.
    5. Now you can use this dll from anywhere, because it become share assembly.

    ReplyDelete
  2. Gacutil -> Global Access Cache Utility.
    Snk -> Strong Name Key
    Gacutil /i -> Here i is for Installation.

    ReplyDelete