如何在Visual Studio 2017(基于目录的项目)中从任意生成任务运行bash?

如何在Visual Studio 2017(基于目录的项目)中从任意生成任务运行bash?,bash,visual-studio,windows-10,visual-studio-2017,windows-subsystem-for-linux,Bash,Visual Studio,Windows 10,Visual Studio 2017,Windows Subsystem For Linux,我正在尝试在Visual Studio 2017中使用bash构建基于DocBook的文档。我在Windows10中使用内置的Linux Windows子系统。我可以启动cmd.exe并运行dir,如MS的示例所示。但是,我需要在bash中运行make ARGS,这就是它失败的原因: '"bash"' is not recognized as an internal or external command, operable program or batch file. 我可以以交互方

我正在尝试在Visual Studio 2017中使用bash构建基于DocBook的文档。我在Windows10中使用内置的Linux Windows子系统。我可以启动cmd.exe并运行
dir
,如MS的示例所示。但是,我需要在bash中运行
make ARGS
,这就是它失败的原因:

  '"bash"' is not recognized as an internal or external command,
  operable program or batch file.
我可以以交互方式运行cmd.exe并毫无问题地启动bash。但它在VisualStudio中失败了。VS2017是否使用了一些特殊的环境?如何通过这些任务使其运行bash?我想我遗漏了一些非常简单和琐碎的东西,但我不知道该从哪里看

基本上,我想对DocBook源代码的路径运行
makeall html
命令

以下是一个最小任务示例:

{
  "version": "0.2.1",
  "tasks": [
    {
      "taskName": "Build all-html",
      "appliesTo": "*",
      "type": "command",
      "command": "bash"
    }
  ]
}

在您的链接中,doc给出了一个使用cmd列出输出的示例:您应该使用
${env.COMSPEC}
来使用
cmd.exe
,然后将
bash
作为参数

{
  "version": "0.2.1",
  "tasks": [
    {
      "taskName": "Build all-html",
      "appliesTo": "*",
      "type": "command",
      "command": "${env.COMSPEC}",
      "args": [
        "bash"
      ]
    }
  ]
}
这将以交互模式运行bash,但您可以使用
bash-c
发出bash命令,如下所示:
bash-c'echo“$PATH”


注意:这将在解决方案的根目录下运行bash(您可以使用
bash-c'echo$PWD'
检查这一点)。

该命令不能像您预期的那样自然找到
bash
,原因是Visual Studio是一个32位程序。这意味着当您指定命令时,它不会使用64位cmd.exe

您可以通过打开32位命令窗口
C:\Windows\SysWOW64\cmd.exe
并从那里尝试
bash
命令来重现Visual Studio正在执行的操作

解决方案是通过
C:\Windows\Sysnative
虚拟文件夹直接调用
bash.exe

您可以找到有关Sysnative文件夹的讨论/解释以及为什么需要它

下面是一个适用于您的示例命令:

{
  "taskName": "print-pwd",
  "appliesTo": "*",
  "type": "command",
  "command": "%WINDIR%\\Sysnative\\bash.exe",
  "args": [
    "-c",
    "pwd"
  ]
}

我也在运行Windows 64位,您是否有一个
COMSPEC
系统环境变量,其值为
%SystemRoot%\system32\cmd.exe
%COMSPEC%
COMSPEC=C:\Windows\system32\cmd.exe