用于脚本的 F#:脚本文件的位置 [英] F# for scripting: location of script file

查看:28
本文介绍了用于脚本的 F#:脚本文件的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆