如何在全局程序集缓存中配置程序集?

发布于 2024-07-06 19:20:06 字数 83 浏览 6 评论 0原文

有没有办法在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

迷鸟归林 2024-07-13 19:20:06

如果我理解你的问题是正确的,不,没有办法做到这一点。

程序集使用加载它的应用程序的配置文件。

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.

心在旅行 2024-07-13 19:20:06

根据您想要实现的场景,您可以将 App.config 文件作为嵌入式资源包含在内,并在需要时提取到磁盘上的某个位置并使用 这个问题

显然,这消除了在不重新编译的情况下实际更改配置的能力,因此有点违背了目的。

另一种选择可能是将配置文件安装到 Application DataCommon 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 or Common Application Data folder, and use the same technique as above.

沒落の蓅哖 2024-07-13 19:20:06

在标准 .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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文