安装到 GAC 的 DLL 路径 [英] Path of DLL installed to the GAC

查看:23
本文介绍了安装到 GAC 的 DLL 路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取已(可能)在 GAC 中注册的 DLL 的(物理)安装路径?此 DLL 是一个控件,它可能托管在 .Net 应用程序以外的其他东西中(包括 VS 以外的 IDE...).

How can I get the (physical) installed path of a DLL that is (may be) registered in GAC? This DLL is a control that may be hosted in things other than a .Net app (including IDEs other than VS...).

当我使用 System.Reflection.Assembly.GetExecutingAssembly().Location 时,它给出了 winntsystem32 中 GAC 文件夹的路径 - 或者在 VS 的设计模式下给出了 VS IDE 的路径.

When I use System.Reflection.Assembly.GetExecutingAssembly().Location, it gives path of GAC folder in winntsystem32 - or in Design mode in VS gives the path to the VS IDE.

我需要获取实际安装物理 dll 的路径 - 或 VS 的 bin/debug 或(发布)文件夹.

I need to get the path where physical dll is actually installed - or the bin/debug or (release) folder for VS.

原因是我需要在此文件夹中获取一个 XML 文件,其中包含在设计模式和运行时使用的配置设置.

Reason is that there is an XML file I need to get at in this folder, with config setting that are used both in design mode and at runtime.

或者如何最好地处理这种情况?我有一个可疑的网络位置,我目前用于设计模式......(不要认为 ApplicationData 文件夹会削减它(但通过 ClickOnce 安装的 .Net 版本已解决,并且可以使用 Clickonce Data文件夹) )

Or how is it best to handle this scenario? I have a dubious network location I am using for design mode at the moment... (Don't think that ApplicationData folder is going to cut it (but have the .Net version soved as that's installed via ClickOnce ans can use the Clickonce Data folder) )

推荐答案

如果将某些内容放入 GAC,它实际上会被复制到 %WINDIR%assembly 下的某个位置,例如

If something gets put in the GAC, it actually gets copied into a spot under %WINDIR%assembly, like

C:WINDOWSassemblyGAC_32System.Data2.0.0.0__b77a5c561934e089System.Data.dll

我假设当您在 GAC 中安装有问题的程序集时检查它的位置时,您会看到类似的内容.这其实是正确的.(在 .NET 1.1 中,当您查看 GAC 程序集的属性时,会列出一个代码库",但这只是为了向您显示运行 gacutil 时原始文件的位置 - 它实际上并未指示将加载什么.) 您可以在此处阅读更多相关信息.

I assume you're seeing something like that when you check the Location of the assembly in question when it's installed in the GAC. That's actually correct. (In .NET 1.1 there was a "Codebase" listed when you looked at a GAC assembly's properties, but that was only to show you where the original file was located when you ran gacutil - it didn't actually indicate what would be loaded.) You can read more about that here.

长话短说,您可能无法做您想做的事.您可能希望将行为切换为相对于主应用程序程序集(Assembly.GetEntryAssembly()) 或将文件放在某个众所周知的位置,可能基于设置的环境变量.

Long story short, you may not be able to do what you want to do. Instead of looking in relation to some assembly that's being loaded (Assembly.GetExecutingAssembly()), you might want to switch the behavior to look relative to the primary application assembly (Assembly.GetEntryAssembly()) or put the file in some well-known location, possibly based on an environment variable that gets set.

这篇关于安装到 GAC 的 DLL 路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆