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

前端 未结 10 740
你的背包
你的背包 2020-12-02 10:20

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

相关标签:
10条回答
  • 2020-12-02 10:57

    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 讨论(0)
  • 2020-12-02 11:04

    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.

    0 讨论(0)
  • 2020-12-02 11:05

    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.

    0 讨论(0)
  • 2020-12-02 11:06

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

    0 讨论(0)
  • 2020-12-02 11:07

    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 讨论(0)
  • 2020-12-02 11:09

    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.

    0 讨论(0)
提交回复
热议问题