Saturday, May 17, 2008

Display your dll in Add Refrence Dialog of Visual Studio 2005

When you are adding any reference (adding assembly) to your project. you open the Add reference dialog it will show you below five tabs.

.Net Lists all .NET Framework components available for referencing.

COM Lists all COM components available for referencing.

Projects Lists Visual Studio projects in the current solution available for referencing. Select assemblies from this tab to create project-to-project references.

Browse Allows you browse additional files to find a component not listed in the current tab and add it to the list.

Recent Displays recently added references.

But if you want to see your assembly in the Add reference dialog under the .Net tab then what should you do?Will add it into GAC? Well! Well! Well just adding into GAC is not enough. Adding into the GAC it doesn't mean it will be visible in the Add Reference Dialog Under ".Net" tab.

What do you mean by adding DLL in to GAC (Global Assembly Cache)
"Adding DLL into GAC means it shared to all application running on same machine. But to add into GAC Assembly must be signed using SN.exe and you can add it using gacutil.exe"

There are three ways to display your assembly into Add Reference dialog.

•Way one: You have to copy your assembly and paste into the "Program Files\Microsoft Visual Studio .NET\Common7\IDE\Public Assemblies" (you can find these assemblies on the .NET tab) see below image.



•Way two: Set a reference path to the directory containing the assembly using the Reference Paths Page, Project Designer (C#).

Select your projects from solution explorer right click on it select property. Select reference property tab give folder path from where assembly resides. see below image.


•Way Three: Set a registry key that specifies the location of assemblies to display. You can either set the key under HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE if you add under HKEY_CURRENT_USER then it will be visible to that user only and if you add key under the HKEY_LOCAL_MACHINE then it will be visible to all users. (Don’t Forget to restart pc after setting this :) )

[HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework\\AssemblyFoldersEx\MyAssemblies]@="AssemblyLocation"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\\AssemblyFoldersEx\MyAssemblies]@="AssemblyLocation"

see below image.


I think way one and two are easy but three is little bit risk can cause harm to your computer.

Quiz for Readers:

Question 1: In default windows application System.Window.Forms.dll assembly is referenced by default when project is created of Window type but when you build the project the System.Window.Forms.dll will not be placed into bin folder why? And if I want to force to put into bin what should I do?

Question 2:
What is the difference between putting the dll files into “\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies” and GAC?

Question 3: I have created project and added reference of the strong name assembly which is located at D:\MySignedAssemblies. Since it is strong name assembly it will be not copied into bin folder. Now time comes to run it to another computer.
What will be happened if another computer does not contain assembly which is referenced by my application?
What will be happened if another computer contains required assembly in GAC instead of bin?

Question 4: How CLR resolved the location of dll files? Can we override the default probing?

Question 5: Where is the physical path of GAC? What is the use of SN.exe and gacutil.exe?

Question 6: What do you mean by delayed signed?

Question 7:If you see the GAC Physical path in Windows Explorer you will be wondered that some dll files have same name then also in the same folder why it is so? (Hint: try to explore the physical path using cmd.exe or command.exe).

No comments: