GAC Assembly Missing in Add Reference dialog - visual-studio

I have an Interop assembly lying in GAC; Windows Explorer clearly shows it listed in the C:\WINDOWS\assembly folder. Yet, when I try to add a reference to it in from Visual Studio, I can't see it anywhere in the Add Reference dialog.
If this is happened to you too, what is the reason for this? And how do I fix this?
(The assembly is actually located in C:\WINDOWS\assembly\GAC_MSIL folder, if you must know.)

Add one of the following registry keys, where is the directory to search, and MyAssemblies is the category of your assemblies. Note HKCU is for the current user and HKLM is for everyone on the same computer.
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework\<version>\AssemblyFoldersEx\MyAssemblies]#="<AssemblyLocation>"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\<version>\AssemblyFoldersEx\MyAssemblies]#="<AssemblyLocation>"

I've created a tool that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.

As other's have pointed out, simply installing an assembly in GAC doesn't ensure it'll show up in the Add Reference Dialog Box. I've found this MSDN page that has the details. See the section To display an assembly in the Add Reference dialog box.

Alternatively, I edited the Project file and added the reference manually.
Install the assembly in GAC. gacutil /i "Foo.dll"
Find the strong name of the assembly. gacutil /l will give you the list from which you can pick.
In the consuming project file add the following line (from the previous step)
<Reference Include="Foo, Version=x.x, Culture=neutral, PublicKeyToken=xxx, processorArchitecture=MSIL" />
And it works. :)

"C:\WINDOWS\assembly" is a special folder which in Windows Explorer will list the assemblies (and the assembly info) within the various sub-folders.
For your case, you might need to point it to the physical path which is "C:\Windows\assembly\GAC_MSIL.....dll" within VS.NET.

You can also map the GAC folder to a virtual drive, and then you can add GAC reference through browse tab.
Manual by MZ-Tools

Use this command under Visual studio command prompt
regsvr32 /u shfusion.dll

Related

How to reference assembly from GAC?

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?
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.
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.
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...
The answer is the Reference Paths in the property windows, you have to set it with the GAC path
Please see my post here:

Missing Public Assemblies folder

Several articles and blogs I have read suggest placing assemblies I wish to make available to T4 in the Visual Studio Public Assemblies folder. This is supposed to be located at C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies, but I have no PublicAssemblies' folder there, onlyPrivateAssemblies. Creating my ownPublicAssemblies` folder doesn't seem to work. Assemblies located here are supposed to be available in the .NET section of the Add References dialogue, and my assembly located there is not.
SOLVED:
I was looking under Program Files, not Program Files (x86). I found Public Assemblies in the latter location.
I don't know about that folder, but MS suggests adding a registry key to make your assemblies available in VS as in this quote from this article: How to display an assembly in the "Add Reference" dialog box
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\MyAssemblies]#="C:\\MyAssemblies"
where MyAssemblies is the name of the folder in which the assemblies reside.
Maybe you can find the answer in another SO question: Can't reference an assembly in a T4 template

visual studio copy dll references to output folder

I am trying to extend a certain application. I am using a DLL which comes bundled with that application to extend its functionality. I am using visual studio 2010 express edition. I added a reference to the dll library. In the reference properties the option "Copy local" is disabled.(greyed out) why is that? I want visual studio to copy the dll to my release folder. If this can't be done is there another way to bundle the dll?
Your comment to Hans answer indicates this is a COM assembly and that you are using Visual Studio 2010.
This means the assembly reference was likely added with the "Embed Interop Types" setting set to true. This has the effect of linking the COM assembly into your binary removing the need to deploy it altogether. The following link has a more detailed explanation
http://msdn.microsoft.com/en-us/library/dd409610.aspx
If you do want to deploy it though then will need to do the following
Click on the reference in the references tab
Hit F4 to bring up the properties grid
Set "Embed Interop Types" to False (this will ungray Copy Local)
Set "Copy Local" to true
It depends on what kind of DLL it is. If it is a COM server then Copy Local is off when you have a PIA registered for that COM server. If it is a regular .NET assembly then it will be off when it is registered in the GAC.
Fix the issue by, respectively, using regasm /u to unregister the PIA or gacutil /u to remove it from the GAC. Do note that you might not want to do this if this DLL requires that its installer is executed on the target machine. Which is likely. Talk to the component vendor or author to find out what you should do.

How can I reference a dll in the GAC from Visual Studio?

This assembly is in the GAC: Microsoft.SqlServer.Management.RegisteredServers.dll
How can I add a reference to this assembly in Visual Studio?
I can view the file in c:\windows\assembly\
As the others said, most of the time you won't want to do that because it doesn't copy the assembly to your project and it won't deploy with your project. However, if you're like me, and trying to add a reference that all target machines have in their GAC but it's not a .NET Framework assembly:
Open the windows Run dialog (Windows Key + r)
Type C:\Windows\assembly\gac_msil. This is some sort of weird hack that lets you browse your GAC. You can only get to it through the run dialog. Hopefully my spreading this info doesn't eventually cause Microsoft to patch it and block it. (Too paranoid? :P)
Find your assembly and copy its path from the address bar.
Open the Add Reference dialog in Visual Studio and choose the Browse tab.
Paste in the path to your GAC assembly.
I don't know if there's an easier way, but I haven't found it. I also frequently use step 1-3 to place .pdb files with their GAC assemblies to make sure they're not lost when I later need to use Remote Debugger.
Registering assmblies into the GAC does not then place a reference to the assembly in the add references dialog. You still need to reference the assembly by path for your project, the main difference being you do not need to use the copy local option, your app will find it at runtime.
In this particular case, you just need to reference your assembly by path (browse) or if you really want to have it in the add reference dialog there is a registry setting where you can add additional paths.
Note, if you ship your app to someone who does not have this assembly installed you will need to ship it, and in this case you really need to use the SharedManagementObjects.msi redistributable.
I've created a tool which is completely free, that will help you to achieve your goal. Muse VSReferences will allow you to add a Global Assembly Cache reference to the project from Add GAC Reference menu item.
Hope this helps Muse VSExtensions
In VS2010, from the Add Rerences window you can click 'Browse' and navigate to C:\Windows\Assembly and add references to the assemblies that you want. Please note that the files may be grouped under different folders like GAC, GAC_32, GAC_64, GAC_MSIL etc.
In VS, right click your project, select "Add Reference...", and you will see all the namespaces that exist in your GAC. Choose Microsoft.SqlServer.Management.RegisteredServers and click OK, and you should be good to go
EDIT:
That is the way you want to do this most of the time. However, after a bit of poking around I found this issue on MS Connect. MS says it is a known deployment issue, and they don't have a work around. The guy says if he copies the dll from the GAC folder and drops it in his bin, it works.
The only way that worked for me, is by copying the dll into your desktop or something, add reference to it, then delete the dll from your desktop.
Visual Studio will refresh itself, and will finally reference the dll from the GAC on itself.
Assuming you alredy tried to "Add Reference..." as explained above and did not succeed, you can have a look here. They say you have to meet some prerequisites:
- .NET 3.5 SP1
- Windows Installer 4.5
EDIT: According to this post it is a known issue.
And this could be the solution you're looking for :)
May be it's too late to answer, but i found a very simple way to do this(without a hack).
Put your dll in GAC (for 3.5 Drag Drop inside "C:\Windows\assembly\")
GoTo Projects --> Properties
Click Reference Path (for 3.5 it's "C:\Windows\assembly\")
and Build
Hope it helps
The relevant files and references can be found here:
http://msdn.microsoft.com/en-us/library/cc283981.aspx
Note the links off it about implementation/etc.
I found this extension for VS 2013 Vitevic GAC Reference.

Visual Studio: How to reference assemblies in Visual Studio?

i have a debug and a release version of an assembly dll.
They are sitting is directories on my computer. For other developers they are sitting in directories on their computer.
For the debug version of the application i want to use the debug assembly. For the release version of the application i want to use the release assembly.
That's the question.
For those not paying attention, there are quite a few issues here. How to reference an assembly on my computer, which after the project is checked into source control becomes a valid path on someone elses computer.
How to have the "References" node be per solution type (Debug, Release).
i tried copying the debug assembly to
\bin\Debug
and the release assembly to
\bin\Release
and added the assembly dll's to source control in the
\bin\Debug
\bin\Release
folders. Then i hope that the assembly would be found in the executable's folder.
Problem with that is that other developer's machines get an error that the assembly dlls could not be overwritten - when CopyLocal is false.
Use a common structure for these DLLs (a common directory-name) and link to this relative.
Example from a .csproj-file:
<Reference Include="utils_xxx, Version=1.2.10.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\common_utils_dllproject_dir\utils\bin\$(Configuration)\utils_xxx.dll</HintPath>
</Reference>
You maybe have to enter this by hand, but once in the repo, it is the same for all. Now you just have to convince your developers to adjust to this directory-layout and -naming.
PS: If you overlooked it: $(Configuration) is the trick to use Release/Debug-DLLs.
Developers must have a folder somewhere on their machine structured like this...
[Parent Folder]
Debug
[Debug Assembly].dll
Release
[Release Assembly].dll
Open the project and add a reference to the Debug assembly from the first step. Check it in.
Have every developer open the project and add a reference path in the project properties. The path should be an absolute path to the Debug folder from the first step.
Have every developer close Visual Studio and edit the [project].user file that is now in the same folder as the project file. Change "Debug" to "$(Configuration)". Save and close.
This should now work. If you select the reference in the Solution Explorer and look at the Path property in the Property Grid, it may not be correct. It's just a VS issue. If you test building in Release and Debug, it should work.
This works because the reference paths that developers set are stored in a user file that never gets checked into source control. Therefore, the paths can be different for every dev. This solution is basically stolen from Leonidas' answer but uses reference paths.
Disclaimer
I don't know all the details of your situation, but I personally wouldn't do this. I would probably GAC the release version of the assembly on the developers' machines. Then I would have a build script that ran on a server that would take care of your complicated scenarios.
Include the project and link to the project? dont know if that does work in your situration...

Resources