How to reference assembly from GAC?

10.7k Views Asked by At

I have installed the strong named assembly TestReflection into the GAC (I am using .NET 4.0 and VS 2010).

Different versions of the TestReflection DLL are in GAC of .NET 4.0 (C:\WINDOWS\Microsoft.NET\assembly\GAC_32\TestReflection\), however, the assembly does not appear in the "Project" -> "Add reference" box of VS 2010.

How can I refer to my assembly deployed in GAC at design time from another project?

This page says that:

You cannot add references from the Global Assembly Cache (GAC), as it is strictly part of the run-time environment.

Referring to this statement, I would like to know how to make your project's DLL shared assembly for other consumers if it's the requirement?

4

There are 4 best solutions below

0
On BEST ANSWER

The dll's shown in the .Net tab of the "Add references" dialog are not actually the ones registered in the GAC. They are found by searching a few paths on your filesystem.

The paths being searched are located by Visual Studio by looking up the following registry entries:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NetFramework\{Version}\AssemblyFoldersEx\

There should be some keys added there already, so if you want your own dll to show up on the .Net tab, you can add it to one of the folders defined there. You could also add a new registry key pointing to a custom folder, which would only contain your own dll's.

The GAC is only meant for loading assemblies at runtime after your application has been deployed, so I don't think you should use it while developing. When you deploy your app, make sure to set "Copy local" to false on your reference so the dll won't be copied to the bin folder, and then install it into the GAC and it will be loaded from there instead.

0
On

The answer is the Reference Paths in the property windows, you have to set it with the GAC path Please see my post here:

0
On

Another simple option would be to manually edit the project file as XML in visual studio (You will have to unload the project first), and simply add node <Reference Include="<name of dll>" /> in MSBuild project file. After reloading the project, VS will pick up the reference without problem.

0
On

If you want to add Global Assembly Cache references to your VS2010 project, there is an extension you can use: Muse.VSExtensions.

It has some quirks but does a decent job. Check it out...