将另一个项目的设置添加到 app.config

发布于 2024-09-09 11:19:32 字数 636 浏览 3 评论 0原文

我用 C# 编写了一个带有设置文件的应用程序(用于在编译时创建 app.config 文件)。该应用程序使用 C# DLL,其中也有一个设置文件。

我从这篇文章中阅读了以下内容:

如果您构建引用 DLL 的项目,则可以将相同的 .settings 文件添加到该项目中,这些设置将出现在应用程序的 app.config 文件中,并且 DLL 将能够读取这些值。如果这些值不在 app.config 中,则 dll 将使用默认值。

我观察到 DLL 存储了默认值,正如它所表明的那样。我右键单击应用程序的项目并选择“添加现有项目”。然后我从 DLL 项目中找到设置文件并将其添加到应用程序的项目中。我希望 DLL 设置文件和应用程序设置文件都包含在应用程序的 app.config 文件中。这样,应用程序的 app.config 文件将覆盖 DLL 中存储的默认值。不幸的是,这并没有发生。

所以,我的问题是,将 DLL 项目中的设置添加到应用程序项目后,如何使应用程序项目识别该文件并在编译时将其设置添加到 app.config 文件中?

I have written an application in C# with a settings file (which is used to create an app.config file at compile time). This application uses a C# DLL which also has a settings file.

I read the following from this post:

If you build a project that references your DLL, you would add the same .settings file to that project and those settings would appear in the app.config file for the app and the DLL would be able to read those values. IF those values aren't in the app.config, the dll will fall back on the defaults.

I observed the DLL storing default values as this indicates it should. I right clicked on my application's project and selected Add Existing Item. Then I found the settings file from my DLL's project and added it to the application's project. My hope was that both the DLL settings file and the application settings file would be included in the application's app.config file. This way, the application's app.config file would override the defaults stored in the DLL. Unfortunately, this isn't happening.

So, my question is after adding the settings from the DLL project to the application project, how do I make the application project recognize the file and add its settings to the app.config file at compile time?

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

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

发布评论

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

评论(1

梦亿 2024-09-16 11:19:32

我不确定你的意思。您是否尝试过以与以下类似的方式包含它?

<appSettings file="dataSettings.config"/>

I'm unsure what you mean. Have you tried including it in a similar way to the following?

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