How to reference assembly from GAC?
Asked Answered
H

4

7

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?

Horrendous answered 17/2, 2011 at 11:31 Comment(1)
The Reference Paths in the Property window lets you to select path for reference assemblies.. choose the GAC pathLeeway
B
9

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.

Bozarth answered 17/2, 2011 at 13:47 Comment(0)
R
4

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.

Reprography answered 26/3, 2014 at 10:52 Comment(0)
T
0

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...

Thearchy answered 2/3, 2012 at 21:9 Comment(0)
L
0

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

Leeway answered 19/6, 2015 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.