Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何获取CSI中当前正在执行的脚本的路径或目录?_C#_C# Interactive_Csi - Fatal编程技术网

C# 如何获取CSI中当前正在执行的脚本的路径或目录?

C# 如何获取CSI中当前正在执行的脚本的路径或目录?,c#,c#-interactive,csi,C#,C# Interactive,Csi,从CSI脚本获取脚本路径的最佳方法是什么?我希望能够从运行在不同目录中的脚本中加载脚本,并且仍然能够访问自己的目录,而不受工作目录的影响。我找不到任何类似nodejs常量的东西。目前,我能找到的最好的方法是确定当前正在执行的脚本的目录非常详细。我不知道是否有一些我不知道的捷径/内置的,但这里有: GetMineDirectory.csx: #!/usr/bin/env csi using System; using System.IO; using System.Runtime.Compile

从CSI脚本获取脚本路径的最佳方法是什么?我希望能够从运行在不同目录中的脚本中加载脚本,并且仍然能够访问自己的目录,而不受工作目录的影响。我找不到任何类似nodejs常量的东西。

目前,我能找到的最好的方法是确定当前正在执行的脚本的目录非常详细。我不知道是否有一些我不知道的捷径/内置的,但这里有:

GetMineDirectory.csx

#!/usr/bin/env csi

using System;
using System.IO;
using System.Runtime.CompilerServices;

static string GetMyPath(
    [CallerFilePath] string path = "")
    => path;

// Do not write in terms of GetMyPath() in case we are called from another script.
static string GetMyDirectory(
    [CallerFilePath] string path = "")
    => Path.GetDirectoryName(path);

Console.WriteLine($"My full path is {GetMyPath()}");

Console.WriteLine($"My directory is {GetMyDirectory()}");