[英]How can I get F# Interactive window to use the same path as the project?
In my project I am opening a file with some relative path to the executable. 在我的项目中,我打开一个文件,其中包含一些可执行文件的相对路径。 I was trying to test my code in the F# Interractive window, but it seems to run from a completely different path. 我试图在F#Interractive窗口中测试我的代码,但它似乎是从一个完全不同的路径运行。 How can I change the path/ make it run from the same path as the project? 如何更改路径/使其从与项目相同的路径运行?
I think __SOURCE_DIRECTORY__
identifier could help here. 我认为__SOURCE_DIRECTORY__
标识符可以在这里提供帮助。
You should use compiler directives to separate between using F# Interactive and compiling F# project. 您应该使用编译器指令来分隔使用F#Interactive和编译F#项目。
#if INTERACTIVE
let path = __SOURCE_DIRECTORY__ + some_relative_path
#else
let path = another_relative_path
#endif
You could set the current working directory when running in FSI: 您可以在FSI中运行时设置当前工作目录:
#if INTERACTIVE
System.IO.Directory.SetCurrentDirectory("<project_path>")
#endif
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.