C# 如何获取CSI中当前正在执行的脚本的路径或目录?
从CSI脚本获取脚本路径的最佳方法是什么?我希望能够从运行在不同目录中的脚本中加载脚本,并且仍然能够访问自己的目录,而不受工作目录的影响。我找不到任何类似nodejs常量的东西。目前,我能找到的最好的方法是确定当前正在执行的脚本的目录非常详细。我不知道是否有一些我不知道的捷径/内置的,但这里有: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
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()}");