Saturday, February 21, 2004

Adding your Assembly in GAC + Making it VS.Net Visible

I just wanted to update you all about some useful information:
You can assume these to be my quick and dirty notes... I am gonna now explain you the process of having a .Net assembly put in GAC and then making it GAC visible...
1.) To put your assembly into GAC you need to have it strong named.... So first step is to go and create a key using the strong name exe of Visual Studio tools.... Go to Visual studio tools and open the command prompt.... Next step is type "sn -k
2.) By doing this you will get a key file on your machine... You now need to bind it with your assembly... Note that the key file in normal scenario will have a "lock" as icon...
3.) Go to assemblyinfo file of your class library (or whatever :-)) and give the path of your this key file in AsemblyKeyFile ibute eg. [assembly: AssemblyKeyFile("C:\\delete\\ClassLibrary1\\bin\\Debug\\somekeyfile.snk")]... Remember ideally you should give a relative path here...
4.) Now again go to VS commond prompt and run gacutil... GacUtil is present in "root directory\Windows\Microsoft .Net\Framework\ the version that you work on" folder... Give the complete path while you run Gacutil... use the switch as "/i "... Now run the Gacutil and your assembly will get entered in the GAC....
5.) Alternatively a simple solution is copying your strong named dll directly in Windows\Assembly, but I feel acedamically you should know about Gacutil too...
6.) Now even after doing all this and having your assembly in GAC you shall not be able to see it when you try to open add referenes... For that there is another trick... See the point is Add Reference is a IDE specific stuff and so you need to alter those setting... for that reason you need to create certain keys in the Registry
7.)To display your assembly in the Add Reference dialog box, you can add a registry key, such as the following, which points to the location of the assembly
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\Debug]@="C:\\MyProjects\\ClassLibrary1\\Bin\\Debug\\" where Debug is nothing but the name of the folder in which the assemblies resides. You will not file any enteries here in case you have never tempered this area... so create this whole structure in the registry... You can create these registry entries under the HKEY_LOCAL_MACHINE root key also. This will change the setting for all of the users on the system. If you create this registry entry under HKEY_CURRENT_USER, this entry will affect the setting for only the current user. Inshort if you want anyone logging the machine is able to see your assembly in the Add References section make the key under HLM or else make it under HCU... When you then next time restart VS.Net you shall be able to find your assembly....
I shall polish this scribbled notes sometimes, but currently it gives sufficient info right!!
So Enjoy!!