Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a simple way to execute scripts when a folder hasn't been opened #354

Closed
chrmarti opened this issue Dec 1, 2016 · 5 comments
Closed
Labels
Issue-Enhancement A feature request (enhancement).

Comments

@chrmarti
Copy link

chrmarti commented Dec 1, 2016

From @TheKnightCoder on December 1, 2016 11:35

  • VSCode Version: 1.8.0-insider
  • OS Version: Windows 7

Steps to Reproduce:

  1. install powershell extension
  2. make a script using $PSScriptRoot (directory of script)
  3. Highlight code and press F8

$PSSScriptRoot is always C:\Program Files (x86)\Microsoft VS Code Insiders

This messes up all my scripts. and this is the only easy way of running code. The only way I can get the script to run correctly is to open the folder and run debug.

Love visual code but why is there no way of running code easily

Copied from original issue: microsoft/vscode#16319

@daviwil
Copy link
Contributor

daviwil commented Dec 1, 2016

Have you tried running your script in the debugger (F5)? Here's what I see:

image

When you run script code with F8, it's basically just executing that text directly so no $PSScriptRoot gets set. Even the ISE doesn't populate $PSScriptRoot in that case. Running the script in the debugger causes the file itself to be executed so $PSScriptRoot is set to the expected path.

@daviwil
Copy link
Contributor

daviwil commented Dec 1, 2016

Sorry, didn't read all of the initial report, seems like you figured out that it works in the debugger. Does this work correctly for you in the ISE or any other editor?

@TheKnightCoder
Copy link

Thanks this has helped. So I guess my issue isn't as bad as I thought.
basically I would like to be able to right click a script "Open with code" then press F5 to run.
Currently you must right click the folder the script is in, "open with code", select the file then press F5.
So opening a single file with code feel kinda useless

@daviwil daviwil changed the title Powershell $PSScriptRoot (No simple way to run scripts) Provide a simple way to execute scripts when a folder hasn't been opened Dec 2, 2016
@daviwil daviwil added the Issue-Enhancement A feature request (enhancement). label Dec 2, 2016
@daviwil daviwil added this to the Backlog milestone Dec 2, 2016
@daviwil
Copy link
Contributor

daviwil commented Dec 2, 2016

Good point, this is one of the confusing aspects of VS Code for people who move over from the ISE. I'll see if I can find a good way to allow script execution easily without opening a folder.

@daviwil
Copy link
Contributor

daviwil commented Dec 6, 2016

I just created another issue to track this request, forgot that this one already existed! I'll close this in favor of the other.

#359

@daviwil daviwil closed this as completed Dec 6, 2016
@daviwil daviwil modified the milestone: Backlog May 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement A feature request (enhancement).
Projects
None yet
Development

No branches or pull requests

3 participants