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 works great. In the Interactive Shell this isn't the case.
I tried to copy the .config file from my bin/Release directory to the obj/Debug & obj/Release dirs, but the Call to ConfigurationManager.AppSettings.Item("key")
always returns null.
Any suggestions how to fix this?
With best regards
App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.
Web. Config is used for asp.net web projects / web services. App.Config is used for Windows Forms, Windows Services, Console Apps and WPF applications.
The application configuration file usually lives in the same directory as your application. For web applications, it is named Web. config. For non-web applications, it starts life with the name of App.
When your app is initialized, the variables in config.py are used to configure Flask and its extensions are accessible via the app. config dictionary – e.g. app. config["DEBUG"] . Configuration variables can be used by Flask, extensions or you.
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:\Svn\trunk\Source\ConfiguredApp\MyConfig.fs]
Binding session to 'C:\Svn\Qar\trunk\Build\Path\ConfiguredApp.exe'...
Notice that you're actually referencing the app.config
when in FSI (rather than the generated .exe.config
.)
Best of luck...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With