When running a ScriptCS .CSX script, is there a way to get the location of the current script file?
Okay, so you can access that using Env.ScriptPath from inside your CSX script.
Env.ScriptPath
The test below shows that in action, and can be found here.
[Scenario] public static void ScriptPathIsSet(ScenarioDirectory directory, string output) { var scenario = MethodBase.GetCurrentMethod().GetFullName(); "Given a script which accesses Env.ScriptPath" .f(() => directory = ScenarioDirectory.Create(scenario) .WriteLine("foo.csx", "Console.WriteLine(Env.ScriptPath)")); "When I execute the script" .f(() => output = ScriptCsExe.Run("foo.csx", directory)); "Then the ScriptPath is displayed" .f(() => output.ShouldContain("foo.csx")); }
Okay, so you can access that using
Env.ScriptPathfrom inside your CSX script.The test below shows that in action, and can be found here.