簡體   English   中英

在運行時檢索 appSettings.json

[英]Retrieve appSettings.json at runtime

有沒有辦法檢索 appSettings.json 的路徑,以便將它們加載到 FileSystemWatcher 實例中?

我找到了解決方案:對於所有好奇的人,我已經解決了如下問題:

string value;
IConfigurationRoot config = new ConfigurationBuilder().AddJsonFile("appsettings.json", false, true).Build();
IConfigurationProvider provider = config.Providers.ToList().First(); //There could be several providers but in my case I have only one
this.provider.Load();//reloads the content of the appSettings.json
this.provider.TryGet("section:subProperty", out value);

如果有人有更好的方法,請發布。 我會很高興閱讀它。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM