6
是否可以使用F#腳本(fsx)文件中的app.config文件?如果是這樣,怎麼樣?我在哪裏放置文件,它會被稱爲什麼?從fsx文件使用app.config
是否可以使用F#腳本(fsx)文件中的app.config文件?如果是這樣,怎麼樣?我在哪裏放置文件,它會被稱爲什麼?從fsx文件使用app.config
@JoeB提供的鏈接問題提供了2個更適合F#Interactive的答案,而不是.fsx腳本。我在下面提供F#腳本一個很好的解決方案:
鑑於這種app.config文件:
<configuration>
<appSettings>
<add key="foo" value="bar"/>
</appSettings>
</configuration>
閱讀foo
這樣:
let appConfigPath = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "app.config")
let fileMap = ExeConfigurationFileMap()
fileMap.ExeConfigFilename <- appConfigPath
let config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None)
let foo = config.AppSettings.Settings.["foo"].Value
Console.WriteLine(foo)
這裏已經回答:http://stackoverflow.com /問題/ 645622/APP-配置和-F-互動 - 不工作 –