为什么我不能使用引用配置文件的 dll

发布于 2024-12-29 21:31:10 字数 536 浏览 0 评论 0原文

我想问这个问题,在 dll 代码中我无法引用 dll.config 文件并且它只能编译到 exe 中并复制到解决方案的任何其他项目,这太疯狂了。

您是否想过当您创建一个 dll 文件 (DataAccess.dll) 时,您希望将其用于具有不同 sql 连接字符串的不同应用程序,但是当您构建解决方案时,它会创建一个 < code>DataAccess.dll.config 文件,但绝不会将其复制到 Winforms 或 Windows 服务的任何其他解决方案中。它就留在那里。

如果您尝试复制配置文件并更改值,您只能得到当时最初编译的内容,即使它看起来像在使用智能感知访问配置设置的 dll 中,编译后这些值也会被忽略。如果您在记事本中打开 dll,您将看到您的设置已编译到 dll 本身中。

令我难以置信的是,我必须将配置文件中的值手动复制到 exe 的配置文件中,才能访问面向对象的智能感知管理器中的配置设置,除非我必须按路径使用硬编码的打开配置文件,并搜索抛出的元素

这是什么交易?没有答案对我来说什么是一种更简单的做事方式,更不用说现实和设计了

I would like to ask this question it is crazy that inside the dll code I can't reference the dll.config file and its only compiled into the exe and copied to any other project to the solution.

Haven't you ever wondered when you created a dll file (DataAccess.dll) for instance which you would like to use for different applications with different sql connection strings but when you build the solution it creates a DataAccess.dll.config file but never copies it into any other solution that is of either a Winforms or Windows service. It just stays there.

If your try to copy the config file over and change the values, you only get what was originally compiled at the time even thought it looks like in the dll your accessing the config settings with intellisense, the values are ignored after compilation. If you open your dll in notepad you will see your settings are compiled into the dll itself.

It boggles my mind that I would have to copy the values from the config file manually into the exe's config file to access configuration settings in an object oriented intellisense manager, except I have to use a hard coded open config file by path and search threw elements

What is the deal? No answer for what to me seams what would be a much easier way of doing things, let alone realistic and by design

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

余厌 2025-01-05 21:31:10

dll 在 .NET 中没有关联的配置文件。

为什么?因为 dll 不是独立的 - 它在可执行文件的上下文中运行。

将读取的配置是与可执行文件关联的配置。

您需要更改 .exe.config 文件才能更新配置值。

A dll does not have an associated config file in .NET.

Why? Because a dll is not stand alone - it runs in the context of an executable.

The config that will be read is the one associated with the executable.

You need to change the .exe.config file in order for the configuration values to be updated.

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