【问题标题】:Is there a way to add the Developer Powershell for VS 2019 as an integrated terminal in VSCode?有没有办法将 VS 2019 的 Developer Powershell 添加为 VSCode 中的集成终端?
【发布时间】:2020-08-20 20:50:00
【问题描述】:

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

【问题讨论】:

    标签: powershell visual-c++ visual-studio-code cmd cl


    【解决方案1】:

    要使 Visual Studio Code 的集成终端类似于 Visual Studio 2019 附带的 Developer PowerShell for VS 2019 控制台,请将以下内容添加到您的 Visual Studio Code 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
    

    【讨论】:

    • 有没有办法同时打开64位版本的开发工具?我试着四处寻找,但似乎没有明确的方法......
    • @Carmo 如果您将SysWOW64 替换为System32,您将获得一个64 位的PowerShell 会话——但我无法告诉您是否一切都会按预期工作——请告诉我们.
    • 似乎启动了一个powershell会话,但工具似乎是x64_86工具。
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2021-08-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-22
      • 2012-04-13
      • 2021-11-04
      相关资源
      最近更新 更多