dotnet / interactive

.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`$PSScriptRoot` is empty (PowerShell kernel)

BalassaMarton opened this issue · comments

Describe the bug

$PSScriptRoot is empty in pwsh cells. It should be initialized to the directory of the notebook.

Please complete the following:

Which version of .NET Interactive are you using? (In a notebook, run the #!about magic command. ):
1.0.522904+cdfa48b2ea1a27dfe0f545c42a34fd3ec7119074

  • OS
    • Windows 11
    • Windows 10
    • macOS
    • Linux (Please specify distro)
    • iOS
    • Android
  • Browser
    • Chrome
    • Edge
    • Firefox
    • Safari
  • Frontend
    • Jupyter Notebook
    • Jupyter Lab
    • nteract
    • Visual Studio Code
    • Visual Studio Code Insiders
    • Visual Studio
    • Other (please specify)

The kernel is unaware of the location of a notebook file and can work without the existence of a file.

When the kernel is started from a notebook though, we do pass the --working-dir option, which sets the current directory. Would it match expectations if $PSScriptRoot were always set to this same directory when available?

When the kernel is started from a notebook though, we do pass the --working-dir option, which sets the current directory. Would it match expectations if $PSScriptRoot were always set to this same directory when available?

Absolutely!

Apologies, I misunderstood how this special variable works.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_automatic_variables?view=powershell-7.4#psscriptroot

$PSScriptRoot

Contains the full path of the executing script's parent directory.

In PowerShell 2.0, this variable is valid only in script modules (.psm1). Beginning in PowerShell 3.0, it's valid in all scripts.

Since there is no actual script file when running code with the .NET Interactive PowerShell kernel, this appears to be behaving as intended.