c# - 覆盖nuget包中的设置
问题描述
我有一个项目,我在其中创建了一个设置文件(右键单击属性并添加设置文件 - 见下图)。
然后我将此项目转换为我已安装到我的网站项目中的 nuget 包
通常在网站中,我可以将以下内容添加到我的 web.config 以覆盖项目的设置:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Nuget.Navigation" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<Nuget.Navigation>
<setting name="SelectedSection" serializeAs="String">
<value>Investors</value>
</setting>
</Nuget.Navigation>
</applicationSettings>
但是,对于 nuget,它只是使用发布 nuget 时编译的初始设置。有没有办法覆盖我的网络项目中的 nuget 设置?
解决方案
不确定为什么设置覆盖不起作用,因为它们与其他 nugets 一起使用。
最后,我们将设置移动到 app.config 文件中,并编写了我们自己的单例以使用配置管理器读取设置:
SelectedSection = ConfigurationManager.AppSettings[nameof(SelectedSection)];
这样我们可以使用应用设置键在 web.config 中覆盖:
<add key="SelectedSection" value="investors" />
推荐阅读
- java - FCM 看不到从 Spring 后端应用程序发送的消息
- javascript - React.js如何在两个组件接受相同参数时提取出一个方法?
- python - 更新json文件的脚本
- python - 如何在不弄乱数字 10 的情况下删除 .0
- javascript - 输出一组字符串的所有值
- jupyterhub - 违反内容安全政策:iframe 中的 JupytherHub
- python - AttributeError:“NoneType”对象没有属性“strip”jupyter notebook
- python - 如何在熊猫上将元组拆分为多列?
- javascript - 如何通过 Chrome 扩展替换 navigator.credentials.create 请求或响应参数?
- r - 在 ggplot 中重新排序数据会导致数据和条形之间不匹配