App.config中和F#交互式不工作工作、App、config

2023-09-04 22:31:33 作者:祖国滴小婲朵

正如我抛我的小宠物的项目,我想存储所有的常量字符串在我的app.config文件(键,XpathEx pressions等)。当我运行编译的exe这一伟大工程。在交互式shell中,这是不是这样的。

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.

我试图在config文件从我的斌/ Release目录复制到OBJ /调试和放大器; OBJ /释放迪尔斯,但电话 ConfigurationManager.AppSettings.Item(钥匙)总是返回null。

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?

致敬

推荐答案

虽然FSI动态生成$ C $下您的输入,使用fsi.exe.config会工作得很好。

While FSI dynamically generates code for your input, using the fsi.exe.config will work just fine.

我创造了这个文件:

<configuration>
    <appSettings>
        <add key="test" value="bar"/>
    </appSettings>
</configuration>

和它保存为fsi.exe.config(程序文件\ fsharp版本\ BIN)。

And saved it as "fsi.exe.config" (program files\fsharp-version\bin).

然后开始FSI:

> #r "System.configuration";;
--> Referenced 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.configuration.dll'

> System.Configuration.ConfigurationManager.AppSettings.["test"];;
val it : string = "bar"

这也工作在Visual Studio。 (但请注意,你需要重置会话以皮卡的变化。)

It also worked from Visual Studio. (But note that you'll need to reset the session to pickup changes.)