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

吃可爱长大的小学妹 提交于 2019-12-19 04:05:46

问题


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 analyze the assemblies located in the GAC.

Bye.


回答1:


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




回答2:


It is in the %windir%\Assembly folder.

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




回答3:


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



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/1557141/how-can-i-get-the-location-of-the-gac-using-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!