question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

F5 on a saved script isn't dot sourcing

See original GitHub issue

Prerequisites

  • I have written a descriptive issue title.
  • I have searched all issues to ensure it has not already been reported.
  • I have read the troubleshooting guide.
  • I am sure this issue is with the extension itself and does not reproduce in a standalone PowerShell instance.
  • I have verified that I am using the latest version of Visual Studio Code and the PowerShell extension.

Summary

Looks like we’re creating a new scope for invocation of script files, leaving any set variables and functions no longer accessible.

PowerShell Version

Name                           Value
----                           -----
PSVersion                      7.2.0-preview.10
PSEdition                      Core
GitCommitId                    7.2.0-preview.10
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visual Studio Code Version

1.60.0
e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
x64

Extension Version

ms-vscode.powershell-preview@2021.11.1

Steps to Reproduce

  1. New file
  2. Add $a = 50
  3. Save it
  4. <kbd>F5</kbd>
  5. Type $a in the PSIC
  6. See it’s not set

Visuals

No response

Logs

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rjmholtcommented, Dec 9, 2021

Probably an oversight. Moving away from dot-sourcing in the API is done for constrained language mode compatibility. In this case (if I’ve read correctly) that doesn’t make sense because the debugger isn’t going to work in CLM. Just remember that anything that dot-sources or uses useLocalScope: false (the default setting) will fail in CLM.

1reaction
JustinGrotecommented, Dec 9, 2021

I feel like I called this out earlier that it was using & instead of . in the code.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Determine if PowerShell script has been dot-sourced
When you run a script from Visual Studio Code or the PowerShell ISE with Debug > Run/Continue ( F5 ), it is implicitly...
Read more >
Troubleshooting - F5 BIG-IP AS3
When sending a large declaration with hundreds of application services, you may experience a 500 error stating that the save sys config operation...
Read more >
Dot sourcing in powershell - Microsoft Q&A
Dot sourcing in powershell. Hi I have two ps1 files in a path C:\Users\myname\Documents\Files\P.ps1. I am trying to call a function 'launch' ...
Read more >
Display and search all variables of a PowerShell script with ...
If you then call the function dot sourced on the console, the variables are available in the Global scope. This procedure might not...
Read more >
Script File - an overview | ScienceDirect Topics
3.6 Script Files. A script file is an m-file that contains a sequence of instructions but is not a function. Unlike a function,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found