开发者

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

How can i get the locat开发者_开发问答ion of the GAC directory using C#?

Exist an entry in the Windows Registry?

UPDATE

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

Bye.


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


There are absolutely valid reasons to access the GAC manually like a folder. Of course, one should be aware of the risk manipulating things there. But read-only access is quite ok, I would say.

Besides the mentioned %windir%\assembly, it might happen that Nir Sofer already did the job for you. He has written GACView.

And hey, it even has a feature to disable the special view in Explorer: Options/Disable Assembly Viewer in Explorer. The folder will then show up as a normal folder. While this worked well on Windows XP, it doesn't on Windows 7 64 Bit, because it's setting it in the 32 Bit version of the Registry. To disable the assembly viewer on Windows 7 64 Bit, start Regedit (64 Bit), go to

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion

and add a new DWORD called DisableCacheViewer with value 1.

To be independent from the directory (which might change), you can enumerate assemblies via the Fusion Registry Key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion\GACChangeNotification\Default

I guess this is how GACView works internally. But it still won't enumerate the .NET 4 assemblies in %windir%\Microsoft.NET\assembly.

A tool which supports .NET 4 is GACBrowser, but it displays less information.


It is in the %windir%\Assembly folder.

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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜