简体   繁体   English

访问和覆盖类库中App.config文件中的值

[英]Access and overwrite values in App.config file in class library

I gone through lot of threads about this topic but did not get any solution. 我讨论了有关该主题的许多主题,但没有得到任何解决方案。

First I created a windows application. 首先,我创建了一个Windows应用程序。 In that I used app.config file to store some variables it worked properly. 在那我使用了app.config文件来存储一些变量,它可以正常工作。 Then the application converted to class library. 然后将应用程序转换为类库。 While extracting the varibles it gives only null values. 提取变量时,它仅提供空值。

Any other option to get or set variables in config file in the class library 在类库的配置文件中获取或设置变量的任何其他选项

Thanks. 谢谢。

If you converted you code to some class library you have to remember that it will reuse web.config/app.config of an application, which references it. 如果您将代码转换为某个类库,则必须记住它会重用引用它的应用程序的web.config / app.config。 So I would suggest to add settings from "old" app.config to the configuration file of an application, which uses your library. 因此,我建议将“旧” app.config中的设置添加到使用您的库的应用程序的配置文件中。

We can not use app.config or web.config in class library. 我们不能在类库中使用app.configweb.config Add app.config for Console/Windows application or web.config file for your web application which calls your class library then application will automatically takes and uses that configuration file. 为控制台/ Windows应用程序添加app.config或为您的Web应用程序添加web.config文件,该文件会调用您的类库,然后应用程序将自动获取并使用该配置文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM