我想從名爲secrets.config
的外部配置文件中讀取我的控制檯應用程序的appSettings
的一部分,而其餘部分我希望從app.config
。從外部配置文件中讀取appSettings的一部分
目前,我有這個設置,但它似乎不是從secrets.config
讀取,它甚至沒有告訴我有關讀取失敗。
以我的app.config
<appSettings file = "secrets.config">
<add key = "Foo" value = "Bar" />
</appSettings>
在secrets.config,這是在同一文件夾中的app.config
<appSettings>
<add key = "Secret" value = "Tiger" />
</appSettings>
在我的代碼
var secret = ConfigurationManager.AppSettings["Secret"];
// secret turns out to be null
的可能的複製[ConfigurationManager.AppSettings使用其他配置文件(http://stackoverflow.com/questions/16425407/configurationmanager-appsettings -use-another-config-file) –
恩,對不起,剛纔意識到你已經採取了Q.答案中詳述的方法之一。 –