FSharp.Configuration icon indicating copy to clipboard operation
FSharp.Configuration copied to clipboard

AppSettings - scripts & redirection

Open isaacabraham opened this issue 9 years ago • 4 comments

I have an .fs file which references the AppSettings provider. If I #load this file from a script, the code does not compile (I imagine because the TP is trying to locate the properties from FSI's app.config). Is there any way around this? The redirection support is only for runtime, not design time.

isaacabraham avatar Jan 14 '16 19:01 isaacabraham

@isaacabraham I think the provider was changed recently, can you check this change: https://github.com/fsprojects/FSharp.Configuration/commit/d88444a44d11aae8f12b65fc2758d34aa0d46a47 or this part of the documentation: http://fsprojects.github.io/FSharp.Configuration/AppSettingsProvider.html#Using-AppSettingsProvider-in-fsx-script

smoothdeveloper avatar Jan 15 '16 03:01 smoothdeveloper

Yes - that's referring rather to runtime redirection though rather than compile-time.

isaacabraham avatar Jan 15 '16 09:01 isaacabraham

@isaacabraham can you try

let [<Literal>] appSettingsPath = __SOURCE_DIRECTORY__ + "/app.config"
type Config = FSharp.Configuration.AppSettings<appSettingsPath>

smoothdeveloper avatar Jan 15 '16 20:01 smoothdeveloper

@isaacabraham in case you didn't figure this out, you have to set both the full path and then SelectExecutableFile, e.g.

// Script name is Script1.fsx
let [<Literal>] appSettingsPath = __SOURCE_DIRECTORY__ + "/Script1.fsx.config"
type Config = FSharp.Configuration.AppSettings<appSettingsPath>
let [<Literal>] executableFile = __SOURCE_DIRECTORY__ + "/Script1.fsx"
Config.SelectExecutableFile executableFile

panesofglass avatar Sep 17 '17 21:09 panesofglass