PowerShell / PowerShell/vscode-powershell
`$PSScriptRoot` is not populated when running a code block (via F8)
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.9k
- Forks
- 547
- PR merge metrics
- No merged PRs in 30d
Description
System Details
- Operating system name and version: Windows 10
- VS Code version: 1.10.2
- PowerShell extension version:
- Output from
$PSVersionTable:
PS C:\Source\neo4j-quick-demo> $pseditor.EditorServicesVersion
Major Minor Build Revision
----- ----- ----- --------
0 11 0 0
PS C:\Source\neo4j-quick-demo>
PS C:\Source\neo4j-quick-demo> code --list-extensions --show-versions
PS C:\Source\neo4j-quick-demo>
PS C:\Source\neo4j-quick-demo> $PSVersionTable
Name Value
---- -----
PSVersion 5.1.14393.953
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.953
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Issue Description
$PSScriptRoot is not populated when running a code block (via F8)
I am trying load DLLs that are in the same directory as the PowerShell script and use $PSScriptRoot to get the location for them.
When running the code in PowerShell it's fine, but using VSCode, when running the code snippet via F8, the variable is not populated.
Repro
- Open VSCode and create a PowerShell (.ps1) file
- Add the following command
Write-Host "$PSScriptRoot\abc" - Select the newly created line and Press F8 to execute the PowerShell in the integrated terminal
Expected result:
<full working path>\abc
e.g. If the script I was editing was in C:\Source I would expect the result to be C:\Source\abc
Actual result:
\abc
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue by selecting the PowerShell line and pressing F8 to execute it in the integrated terminal, using the documented Windows and VS Code setup. Trace the F8 code-block execution path and verify that $PSScriptRoot resolves to the script directory rather than producing only \abc.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell, typescript
- Domain
- developer-experience, devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100