F# Interactive can work with executables that rely on app.config
files.
The way to do this is to have an .fs
file in your project that loads your .config
conditional on the COMPILED
define so:
let GetMyConfig() =
let config =
#if COMPILED
ConfigurationManager.GetSection("MyConfig") :?> MyConfig
#else
let path = __SOURCE_DIRECTORY__ + "/app.config"
let fileMap = ConfigurationFileMap(path)
let config = ConfigurationManager.OpenMappedMachineConfiguration(fileMap)
config.GetSection("MyConfig") :?> MyConfig
#endif
then in your script file reference the executable and #load
the .fs
file so:
#I "../Build/Path
#r "ConfiguredApp.exe"
#load "MyConfig.fs"
On executing these three lines you will see a message similar to the following in the FSI window:
[Loading C:SvnrunkSourceConfiguredAppMyConfig.fs]
Binding session to 'C:SvnQarrunkBuildPathConfiguredApp.exe'...
Notice that you're actually referencing the app.config
when in FSI (rather than the generated .exe.config
.)
Best of luck...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…