tags:

views:

855

answers:

4

Hi, How can i get the location of the GAC directory using C#?

Exist an entry in the Windows Registry?

UPDATE

I need the location because, i want to enumerate and analize the assemblies located in the GAC.

Bye.

A: 

Is it not always %windir%\assembly ?

edit:

c:\Windows>dir \windows\assembly
 Volume in drive C has no label.
 Volume Serial Number is C8BC-2EBD

 Directory of c:\windows\assembly

08/14/2009  03:06 AM    <DIR>          GAC
07/28/2009  03:07 AM    <DIR>          GAC_32
09/08/2009  10:57 PM    <DIR>          GAC_MSIL
08/15/2009  07:35 PM    <DIR>          NativeImages_v2.0.50727_32
09/08/2009  10:57 PM    <DIR>          temp
09/08/2009  09:47 PM    <DIR>          tmp
               0 File(s)              0 bytes
               6 Dir(s)   4,560,822,272 bytes free
Cheeso
No, it is not always going to be `%windir%\Assembly`. It happens to be that way right now, but it's current location and it's structure is not guaranteed to remain the same, nor is putting files in there a reasonable API for installing or reading information from the GAC.
Robert P
@Robert it is highly unlikely Microsoft will change it, since doing so would be a great risk to backward compatibility. (Not to say it's OK to try to do this)
Rex M
A: 

It is in the %windir%\Assembly folder.

Dan got the answer first as far as a code example though.

Alex Moore
are you going to keep it a secret then?
Cheeso
Probably because if you're looking for the GAC folder, you're doing something wrong. The "location" of the GAC is NOT fixed, and there is not an API for looking it up.
Robert P
I fully agree with you that there may be something (very) wrong if he needs that folder. On the other hand maybe he just wants do develop an info tool. So why not. In fact that would even make sense as the folder is not openable in Explorer by default.And the code sample shows that it is not hard to get the path.
Foxfire
Note that for .NET 4.0 Beta 2 the location of the GAC assemblies no longer defaults to %windir$\assembly.
Joe Kuemerle
A: 

Let the runtime manage its assemblies and trust that they'll be there. If you need to install something use gacutil. If you need to uninstall something use gacutil. If you need to access an assembly then add a reference to it in your project. If you need to interact with the GAC on someone else's machine, do what @Dan says and use MSI and friends.

Otherwise DO NOT TOUCH THE GAC

overstood
gacutil is for developers; production applications should use MSI and friends.
Dan
@Dan, that's absolutely correct. I'll edit my post.
overstood
+3  A: 

If you want to enumerate the stuff in the GAC (e.g. writing an system administration tool) your best option is to use the fusion.dll although this requires some interop code on your side.

Link to Microsoft for Fusion.DLL Documentation

Foxfire
This looks to be the best supported technique to "enumerate and analize" stuff in the GAC.
Dan
Trust me, you don't want to rely on where the GAC "appears" to be in the filesystem. It can change.
Joe Kuemerle
Thats exactly why using Fusion might be a good idea here.
Foxfire
Exactly. Now that .NET 4.0 Beta 2 is public we see that MS has moved the location of the GAC to %SYSTEM%\Microsoft.NET\assembly\GAC* directories so we know that it is still best to use Fusion to find it.
Joe Kuemerle