I have the following section in my appsettings.json
file for my aspnet vnext application.
我的appsettings.json文件中有以下部分,用于我的aspnet vnext应用程序。
"Settings": {
"IgnoredServices" : ["ignore1", "ignore2"]
}
}
This works quite happily in mapping using IOptions<Settings>
, where the settings class is
这在使用IOptions
public class Settings
{
public List<string> IgnoredServices { get; set; }
}
However, I am struggling to override this json file option with an environment variable form. I have tried
但是,我正在努力用环境变量形式覆盖这个json文件选项。我努力了
Name Settings:IgnoredServices
Value "ignore1", "ignore2"
名称设置:IgnoredServices值“ignore1”,“ignore2”
and
和
Name Settings:IgnoredServices
Value ["ignore1", "ignore2"]
名称设置:IgnoredServices值[“ignore1”,“ignore2”]
Neither seem to map correctly and I get the following error message
似乎都没有正确映射,我收到以下错误消息
System.InvalidOperationException: Failed to convert '["ignore1", "ignore2"]'
to type 'System.Collections.Generic.List`1[System.String]
What format should I put my values into environment variables to be successfully interpreted as the correct list of strings?
我应该将我的值放入环境变量的哪种格式才能成功解释为正确的字符串列表?
1 个解决方案
#1
2
Try this:
尝试这个:
Name Settings:IgnoredServices:0
名称设置:IgnoredServices:0
Value ignore1
值ignore1
Name Settings:IgnoredServices:1
名称设置:IgnoredServices:1
Value ignore2
值ignore2
#1
2
Try this:
尝试这个:
Name Settings:IgnoredServices:0
名称设置:IgnoredServices:0
Value ignore1
值ignore1
Name Settings:IgnoredServices:1
名称设置:IgnoredServices:1
Value ignore2
值ignore2