55

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\

10 Answers 10

64

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:

  1. Open the windows Run dialog (Windows Key + r)
  2. 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)
  3. Find your assembly and copy its path from the address bar.
  4. Open the Add Reference dialog in Visual Studio and choose the Browse tab.
  5. 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.

9
  • I was recently watching a Channel 9 video or something similar and briefly saw that the instructor's add reference window included a GAC option (don't remember exactly). I don't know if that was a homemade add-in or if there's one out there available. Has anyone seen this?
    – xr280xr
    Apr 19, 2011 at 13:40
  • 1
    "GAC_MSIL is not recognised as internal or external command" in Win7
    – Rakesh
    Dec 9, 2013 at 10:46
  • 2
    @Rakesh, it works in Win7. Type the full path as shown in the answer, not only gac_msil Apr 22, 2015 at 10:10
  • 2
    May also need to search here: C:\Windows\Microsoft.NET\assembly
    – marknuzz
    Oct 24, 2017 at 1:05
  • 1
    Thanks, @DanielDušek. This answer was from the Windows XP/.NET 2.0 days. XP had something called the Assembly Cache Viewer shell extension from shfusion.dll that provided a special (but restrictive) view of the directory. For whatever reason (which I'm sure makes perfect sense to someone more familiar with the shell), hitting the path from the run dialog bypassed it. I believe it was also possible to disable it in the registry. It became obsolete with .NET 4. This is a good walk down memory lane on the topic: codeproject.com/Articles/4352/…
    – xr280xr
    Dec 23, 2021 at 18:21
20

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.

2
  • Your link is broken. It looks like ther eis now a NuGet package. But there's also still downloads of the MSI, like here.
    – jpmc26
    Jul 18, 2018 at 20:07
  • 1
    This answer was posted 9 years ago ! - edited to remove the link, but honestly this question and answer are basically historical.
    – Tim Jarvis
    Jul 20, 2018 at 4:21
15

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

2
  • Is there any way to make it work with Visual Studio Express Edition? Mar 28, 2012 at 18:36
  • @Fetchezlavache: I have unofficially modified the extension to support VS2012 and VS2013. It is available for download here Jun 25, 2014 at 3:47
8

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.

6

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.

2
  • It is not there for some reason!
    – yankman
    Jan 14, 2009 at 21:14
  • On the page you linked they now (since 17-Nov-2010) mention that the issue has been fixed. Jan 11, 2011 at 14:39
4

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.

3

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 :)

1

May be it's too late to answer, but i found a very simple way to do this(without a hack).

  1. Put your dll in GAC (for 3.5 Drag Drop inside "C:\Windows\assembly\")
  2. GoTo Projects --> Properties
  3. Click Reference Path (for 3.5 it's "C:\Windows\assembly\")
  4. and Build

Hope it helps

0

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.

0

I found this extension for VS 2013 Vitevic GAC Reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.