有没有办法在 VSCode 中将 Developer Powershell for VS 2019 添加为集成终端?

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

我正在从事一个需要我使用 MSVC 编译 C++ 代码的项目,但我主要使用 VSCode。因此,我想知道是否有办法将 Developer Powershell 添加为集成终端,这样我就可以在不需要打开辅助终端的情况下进行编译。我想直接从 Developer PS 本身打开 VSCode,但由于这主要是一个临时项目,因此似乎有很多重复性工作。我尝试对 VSCode 使用 Shell launcher 扩展名,但它没有用。有什么我可以做的吗?

要使 Visual Studio 代码的集成终端像 Visual Studio 2019 附带的 Developer PowerShell for VS 2019 控制台一样,请将以下内容添加到您的 Visual Studio 代码 settings.json文件(> Preferences: Open Settings (JSON)):

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

"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"

请注意,32 位 版本的 PowerShell 已启动,然后导入模块并从该模块调用函数。

我已经从以下快捷方式文件 (*.lnk) 的“属性”对话框中获取(并改编)了命令 - 其详细信息可能因 Visual Studio 版本而异 -

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools\Developer PowerShell for VS 2019.lnk

mklement0 答案的一个变体是在 Visual Studio 代码 settings.json 中使用 terminal.integrated.profiles.windows,如下所示:

    "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}"
            ]
        }
    }

在我的机器上 Visual studio 2022 更新

    "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}"
        ]
    }
}