用于脚本的F#:脚本文件的位置 [英] F# for scripting: location of script file
问题描述
在F#脚本文件(.fsx)中,如何确定当前正在执行的.fsx文件的位置?我想解析相对于它的路径.
In an F# script file (.fsx), how can I determine the location of the .fsx file currently executing? I'd like to resolve paths relative to it.
我尝试了Assembly.GetExecutingAssembly().CodeBase
,但是显然不能在动态程序集"中使用.
I tried Assembly.GetExecutingAssembly().CodeBase
but that doesn't work in a "dynamic assembly", apparently.
推荐答案
从F#规范中提取:
_ _SOURCE_DIRECTORY __ -用文字逐字记录字符串替换,该字符串指定包含当前文件的目录的名称,例如C:\ source.当前文件的名称由文件中的最新line指令确定.如果未提供任何行指令,则该名称由与System.IO.Path.GetFullPath结合使用的命令行编译器确定.
__SOURCE_DIRECTORY__ - Replaced by a literal verbatim string that specifies the name of the directory that contains the current file, for example, C:\source. The name of the current file is determined by the most recent line directive in the file. If no line directive has been given, the name is determined by that given to the command-line compiler in combination with System.IO.Path.GetFullPath.
_ _SOURCE_FILE __ -由包含当前文件名称的文字逐字字符串替换,例如file.fs
__SOURCE_FILE__ - Replaced by a literal verbatim string that contains the name of the current file, for example, file.fs
这篇关于用于脚本的F#:脚本文件的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!