如何在全局程序集缓存中配置程序集?
有没有办法在 GAC 中配置程序集? 我想使用 System.Configuration 将自定义配置添加到我的程序集中。
梅尔
Is there a way to configure an assembly in GAC? I want to add a custom configuration to my assembly with System.Configuration.
Mher
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果我理解你的问题是正确的,不,没有办法做到这一点。
程序集使用加载它的应用程序的配置文件。
If I understand your question right, no, there is no way to do this.
An assembly uses the configuration file of the application that loads it.
根据您想要实现的场景,您可以将 App.config 文件作为嵌入式资源包含在内,并在需要时提取到磁盘上的某个位置并使用 这个问题。
显然,这消除了在不重新编译的情况下实际更改配置的能力,因此有点违背了目的。
另一种选择可能是将配置文件安装到
Application Data
或Common Application Data
文件夹中,并使用与上述相同的技术。Depending on what scenario you are trying to achieve, you could include your App.config file as an embedded resource and when required extract to somewhere on disk and load using the advice given to this question.
Obviously this removes the ability to actually change the config without recompiling, so kind of defeats the purpose.
Another option might be to have the config file intalled into either the
Application Data
orCommon Application Data
folder, and use the same technique as above.在标准 .NET 框架中没有简单的方法可以做到这一点。 如果您使用 Enterprise Library 配置组件,FileConfigurationSource 类将允许您将配置文件定位到另一个位置。 还有一种偷偷摸摸的方法可以使用标准 ConfigurationManager 的 OpenExeConfiguraion 方法来完成此操作。 我在博客上写了一篇名为 创建配置对象的虚拟目标描述了它是如何完成的。
There's no easy way to do this in the standard .NET framework. If you use the Enterprise Library configuration components, the FileConfigurationSource class will allow you to target a configuration file in another location. There's also a sneaky way to use the standard ConfigurationManager's OpenExeConfiguraion method to do it. I wrote a post on my blog called Creating Dummy Targets For Configuration Objects that describes how it's done.