App.config and F# Interactive not working

前端 未结 6 1301
陌清茗
陌清茗 2020-12-17 10:53

As I\'m polishing my little pet project, I\'m trying to store all the constant strings in my app.config file (Keys, XpathExpressions etc). When I run the compiled exe this w

6条回答
  •  粉色の甜心
    2020-12-17 11:25

    I think I provide below the best of both worlds from the two most voted answers above (especially for people writing fsx scripts):

    Given this app.config file:

    
        
            
        
    
    

    Read foo this way:

    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)
    

提交回复
热议问题