How to reference GAC assemblies using VS2005- how funny is this.

I've just discovered how I add a reference to an assembly in the GAC from a C# solution using VS2005.
I find it rather incredible that it is this difficult to do. And I really don't think I've missed anything here.
1. Go into Registry and disable the GAC cache viewer:
HKLM\SOFTWARE\Microsoft\Fusion, DisableCacheViewer- set to non zero.
You have to do this as the cache viewer prevents you from copying assemblies out from the GAC.
2. Go into the GAC folder and copy the assemblies you want to reference to somewhere else on your machine.
3. Add the reference from your solution by browsing to the copy of the assembly you made in step 2.
That's ridiculous. I thought the idea of the GAC was to use it for shared assemblies. Why is it so difficult to use these assemblies from VS 2005


Answer this question

How to reference GAC assemblies using VS2005- how funny is this.

  • Solomonsd21

    What exactly is the assembly that you are trying to reference

    I've had no problem with any assembly in the GAC, so I can only assume that there's something gone a bit screwy on your system, or there's a bug on all systems with some of the assemblies, but they are assemblies that most people don't want to reference.

    If you say which assembly you are trying to reference, I'll have a look on my system to see if it's there.

    [EDIT] Ah, I see it's one of your own assemblies that you've added to the GAC. Is that correct Did you strong-name sign your assembly

    I've had no problems adding my own assemblies to the GAC. You can be sure that if it didn't work, there'd be LOTS of people complaining about it! Therefore, I must assume that there's a bug that doesn't affect many people, or there's something funny about your assemblies or how you're adding them to the GAC.

     

     


  • BAnVA

    Ernst Kuschke wrote:

    If you want to reference an assembly that is not in the GAC, just click the browse button and browse to it. Just make sure that you include these referenced assemblies in your installation.

    *sigh*
    you can't browse to assemblies in the GAC when adding a reference. That's my main point.....

  • DeanB61

    Normally on the Dev machine, you'd have a copy of the "core" assemblies outside the GAC (since you build them outside the GAC or - in the case of third party assemblies - the DLLs are installed outside the GAC for development use). You can therefore reference those assemblies outside the GAC.

    On the end user's PC, the assemblies can be installed into the GAC, and will thus automatically be used if they are present.

    That's the way we work with our own, and third-party, assemblies (which is why we don't get any problems).

    I think the key thing is: Development PC <> User PC


  • Game Squirrel

    If you want to reference an assembly that is not in the GAC, just click the browse button and browse to it. Just make sure that you include these referenced assemblies in your installation.



  • blackwidow25

    Ah, I see. Is it related to this

    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=8234e091-81f8-4778-9487-371901d0fa45

    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=ac46da5e-ce96-48a8-9cee-d10b1e0be26b

    http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx feedbackid=89a1c9c7-c7f9-4676-853f-c3a2fa40f8bf

     


  • flep

    Yes exactly.
    To be honest I don't understand why MS have designed it this way.
    Can someone explain this comment made by the VS team
    The fact that we do not allow you to reference from the GAC is by design. The GAC is meant to be a runtime environment; the user does not necessarily have the right to reference/redistribute/build against assemblies contained in the GAC.
    What are they talking about The whole idea of the GAC is to share assemblies, so why on earth does the user not have the right to reference it at compile time
    e.g. we are building software that integrates with one of our "core" products.
    The core product installs assemblies to the GAC. The products that integrate with it can assume that the assemblies that it requires are in the GAC because it is always installed on a computer with our core product already installed. So we want to build and reference these core assemblies in the GAC.
    Seems reasonable to me.

  • Bdenison

    Umm, you're wrong.
    The .NET tab does NOT show all of the assemblies that are located on the system, nor does it show all of the assemblies in the GAC.
    And yes, I know the CLR will not actually use the assemblies copied from the GAC, at runtime it will resolve the assemblies to the GAC. The only reason for having to copy them from there is so you can add a reference in Visual Studio 2005.
    If you really don't belive me, try adding one of your own assemblies to the GAC, and then try referencing it from another solution....

  • jstamets

    hmmm, interesting.
     
    We have a slightly different scenario in that our core product is potentially installed in both scenarios, both on end user and development machines.
     
    I did consider maybe installing a copy of the GAC assemblies to aanother folder, just to make it easier for developers to reference our assemblies, maybe we will do this.
     
    But I'd only be doing that just to work around this "feature" of not being able to reference GAC assemblies directly.

  • recordus

    Why on earth would you want to copy assemblies from the GAC and move them outside of it In many ways you are causing yourself more problems without knowing it.

    In VS2005 when you add a reference, from within the .NET tab you are being shown all of the assemblies that are located on the system... those within the directory X:\Windows\Microsoft.NET\Framework\v2.0.50727 and other similar dirs (where X is the drive you have the framework installed to) are in the GAC. Remember, as far as the actual file locations are concerned, the GAC is just a set of folders with logic running elsewhere that manages which file is which and which version is which.

    When you copy files from the GAC and use them externally... yes, you are still referencing them... only when you run your app later, the assemblies you copied out are not being used, instead those in the GAC are because of the way the runtime locates assemblies (http://msdn.microsoft.com/library/default.asp url=/library/en-us/cpguide/html/cpconhowruntimelocatesassemblies.asp).



  • Ramachandran.d

    Yes, I am referencing our own assemblies.

    Yes, we signed them, otherwise we wouldn't have been able to get them in the GAC.

    I haven't had any problems adding them to the GAC.

    The difficulty comes when you want to reference GAC assemblies from another solution.

    And lots of people are complaining about it, but seemingly there are lots of people that don't need to reference assemblies in the GAC which I find quite suprising, as lots of people haven't come across this problem.


  • How to reference GAC assemblies using VS2005- how funny is this.