Is there a way to add the Developer Powershell for VS 2019 as an integrated terminal in VSCode?
Asked Answered
K

7

7

I'm working on a project that requires me to compile C++ code using MSVC, but I am working mostly with VSCode. As such, I was wondering if there is a way for me to add the Developer Powershell as an integrated terminal, so that I can compile without needing a secondary terminal open. I thought of just opening VSCode from the Developer PS itself, but since this is mostly a temporary project it seemed like a lot of repetitive work. I tried using the Shell launcher extension for VSCode but it didn't work. Is there anything I can do?

Kiowa answered 6/5, 2020 at 1:41 Comment(0)
N
4

Update:

  • This answer is obsolete. For a current solution, see Dan Fiego's answer, which uses the dedicated Launch-VsDevShell.ps1.ps1 script that has since been introduced, and shows a JSON object that you can place inside the "terminal.integrated.profiles.windows" property in settings.json, which makes a shell named Developer PowerShell for VS 2022 available in the integrated terminal.

To make Visual Studio Code's integrated terminal act like the Developer PowerShell for VS 2019 console that comes with Visual Studio 2019, add the following to your Visual Studio Code settings.json file (> Preferences: Open Settings (JSON)):

"terminal.integrated.shell.windows": "C:/Windows/SysWOW64/WindowsPowerShell/v1.0/powershell.exe"

and

"terminal.integrated.shellArgs.windows": "-noe -c Import-Module 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell ed9e071d"

Note that a 32-bit version of PowerShell is started, followed by import of a module and a call to a function from that module.

I've taken (and adapted) the commands - whose details may differ depending on the Visual Studio version - from the Properties dialog of the following shortcut file (*.lnk):

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\Developer PowerShell for VS 2019.lnk
Nadabb answered 7/5, 2020 at 19:22 Comment(3)
Is there a way to open a 64 bit version of the development tools as well? I tried looking around for it but there doesn't seem to be a clear way...Kiowa
@Kiowa If you replace SysWOW64 with System32, you'll get a 64-bit PowerShell session - but I can't tell you whether everything will work as intended - do let us know.Nadabb
It seems to start a powershell session, but the tools seem to be x64_86 tools.Kiowa
M
7

I found this in March of 2023, looking for an answer to this question. At this point, Microsoft documents a Launch-VsDevShell.ps1 script that is the recommended way to start a developer PowerShell terminal. I tried simply making that script the path parameter in the above JSON, but that didn't work. Then I tried making it the sole member of args, and that seemed to work briefly and then exit. Finally, I added -NoExit and that seems to work like a charm!

Of note for anyone coming after me, I'm using Visual Studio Community 2022 with an x86-64 install (so it's under C:\Program Files\.

        "Developer PowerShell for VS 2022": {
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "args": [
               "-WorkingDirectory",
               "${workspaceFolder}",
               "-NoExit",
               "C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/Tools/Launch-VsDevShell.ps1"
            ]
        }
Mimesis answered 25/3, 2023 at 16:42 Comment(1)
This looks promising, but I think you need "-File", before the path to the .ps1 file for this to work. Also worth mentioning that this snippet is presumably meant to be placed inside the "terminal.integrated.profiles.windows" property in the settings.json file.Nadabb
P
5

A variation of the answer of mklement0 is to use terminal.integrated.profiles.windows in the Visual Studio Code settings.json like this:

    "terminal.integrated.profiles.windows": {
        "Developer PowerShell for VS 2019": {
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "path": "{env:windir}\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe",
            "args": [
                "-noe",
                "-c",
                "&{Import-Module 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell 7068d947}"
            ]
        }
    }
Pungent answered 1/11, 2021 at 11:25 Comment(1)
path is unnecessary since you already have "source": "PowerShell". Doing this also allows you to use powershell 7Detent
N
4

Update:

  • This answer is obsolete. For a current solution, see Dan Fiego's answer, which uses the dedicated Launch-VsDevShell.ps1.ps1 script that has since been introduced, and shows a JSON object that you can place inside the "terminal.integrated.profiles.windows" property in settings.json, which makes a shell named Developer PowerShell for VS 2022 available in the integrated terminal.

To make Visual Studio Code's integrated terminal act like the Developer PowerShell for VS 2019 console that comes with Visual Studio 2019, add the following to your Visual Studio Code settings.json file (> Preferences: Open Settings (JSON)):

"terminal.integrated.shell.windows": "C:/Windows/SysWOW64/WindowsPowerShell/v1.0/powershell.exe"

and

"terminal.integrated.shellArgs.windows": "-noe -c Import-Module 'C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell ed9e071d"

Note that a 32-bit version of PowerShell is started, followed by import of a module and a call to a function from that module.

I've taken (and adapted) the commands - whose details may differ depending on the Visual Studio version - from the Properties dialog of the following shortcut file (*.lnk):

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\Developer PowerShell for VS 2019.lnk
Nadabb answered 7/5, 2020 at 19:22 Comment(3)
Is there a way to open a 64 bit version of the development tools as well? I tried looking around for it but there doesn't seem to be a clear way...Kiowa
@Kiowa If you replace SysWOW64 with System32, you'll get a 64-bit PowerShell session - but I can't tell you whether everything will work as intended - do let us know.Nadabb
It seems to start a powershell session, but the tools seem to be x64_86 tools.Kiowa
E
4

Update for Visual studio 2022 on my machine

    "terminal.integrated.profiles.windows": {
    "Developer PowerShell for VS 2022": {
        "source": "PowerShell",
        "icon": "terminal-powershell",
        "args": [
            "-noe",
            "-c",
            "&{Import-Module 'C:/Program Files (x86)/Microsoft Visual Studio/2022/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll'; Enter-VsDevShell ed9e4c07}"
        ]
    }
}
Emancipator answered 28/3, 2022 at 2:16 Comment(2)
Follow up question, can I get it to start in the workspace root with these options?Foolhardy
@EduardoSerna Kind of. You can add -WorkingDirectory C:\\Users\\eduar\\path\\to\\repo as another argument (or two), but then it's hardcoded to that path. I haven't been able to find a way to get it to just automatically go to the workspace folder.Eyestrain
T
1

I had issues with Windows style paths on my machine and I have only installed Build Tools so the path is changed as well. My settings.json looks like this now:

"Developer PowerShell for VS 2022": {
    "overrideName": true,
    "source": "PowerShell",
    "icon": "terminal-powershell",
    "args": [
        "-NoExit",
        "& \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\Common7\\Tools\\Launch-VsDevShell.ps1\"",
    ]
}

Additionally I had to change the Execution-Policy for PS scripts:

Set-ExecutionPolicy -ExecutionPolicy Bypass

Execute in Admin Powershell at your own risk.

Tildi answered 19/11, 2023 at 8:33 Comment(0)
C
-1

Expanding on all answers here to make it behave a little more as expected. Add this to your settings.json:

"terminal.integrated.profiles.windows": {
        "Developer PowerShell for VS 2022": {
            "overrideName": true,
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "args": [
                "-WorkingDirectory",
                "${workspaceFolder}",
                "-NoExit",
                "C:/Program Files/Microsoft Visual Studio/2022/Professional/Common7/Tools/Launch-VsDevShell.ps1",
                "-SkipAutomaticLocation"
            ]
        }
    },

The -WorkingFolder ${workspaceFolder} and SkipAutomaticLocation will make the terminal start in your current workspace.

The "overrideName": true will override the default pwsh name in the list of terminals once it's opened and name it Developer PowerShell for VS 2022:

enter image description here

I couldn't find a way to dynamically get the Visual Studio installation directory unfortunately so everyone will have to put in their absolute path.

Crawford answered 25/10, 2023 at 14:17 Comment(2)
Can vswhere.exe help find it?Typify
-SkipAutomaticLocation seems to cause an errorMatronize
T
-1

Tried existing answers, not works perfectly.

My working config is the following, which navigate to current working directory (the root directory that VSCode opens):

    "terminal.integrated.profiles.windows": {
        "Developer PowerShell for VS 2022": {
            "overrideName": true,
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "args": [
                "-NoExit",
                "& \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\Common7\\Tools\\Launch-VsDevShell.ps1\"",
                "-SkipAutomaticLocation"
            ]
        }
    },
Typify answered 28/5, 2024 at 17:28 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.