How to run bash from arbitrary build tasks in Visual Studio 2017 (directory-based project)?

bahrep

I'm trying to enable custom build tasks to use bash to build DocBook-based documentation in Visual Studio 2017. I use built-in Windows Subsystem for Linux in Windows 10. I can launch cmd.exe and run dir as in MS's examples. However, I need to run make ARGS in bash and that's where I it fails with:

  '"bash"' is not recognized as an internal or external command,
  operable program or batch file.

I can run cmd.exe interactively and start bash without any problems. But it fails in Visual Studio. Does VS2017 use some special environment? How to make it run bash via those tasks? I guess that I am missing something very simple and trivial, but I don't understand where to look at.

Essentially, I want to run make all-html command against the path with my DocBook sources.

Here is a minimal task example:

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

The reason the command doesn't naturally find bash like you would expect is because Visual Studio is a 32-bit program. This means that it won't use the 64-bit cmd.exe when you specify commands.

You can reproduce what Visual Studio is doing by opening a 32-bit command window C:\Windows\SysWOW64\cmd.exe and trying the bash command from there.

The solution is to invoke bash.exe directly via the C:\Windows\Sysnative virtual folder.

You can find a discussion/explanation of the Sysnative folder and why it is necessary here in the official Bash on Windows GitHub.

Here is an example command that should work for you:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to install grunt outside of a project and run tasks from the project directory

Build project in 2017 Visual Studio from the command line?

Visual Studio 2017 and CMake - How to set the build directory

How to set working directory for Visual Studio 2017 RC CMake Project

how use properties from Directory.Build.props in Import from project file of Visual Studio

How can I build an existing Windows-only Visual Studio project from Bash using WSL

How to prevent visual studio 2017 from build javascript?

Visual Studio 2017 - How to create a project from the source using CMake?

How to run gulp tasks in Visual Studio for Mac?

How to Delete Additional build files from the Project Solution in visual studio

How to build for XP in Visual Studio 2017?

How to build OpenSSL on Windows with Visual Studio 2017?

Debug/Run from Visual Studio 2017 very slow after one build

How to create MVC project in visual studio 2017?

how to send visual studio project 2017 to github?

How to clone and rename a project in Visual Studio 2017?

How to get C# (.net core) project directory path in Visual Studio 2017 RC3?

How to move project .netcore in visual studio to run on windows from mac

Nuget CLI in Visual Studio 2017 - How to run?

How to get Visual Studio 2017 to compile TypeScript on build in class library project (new .net core style .csproj)

How to build x64 assembly project in visual studio 2017/2019

How to use Visual Studio 2017 with TFS Visual Studio Build Step

ASP.NET Core: "The project doesn't know how to run the profile Docker." on Visual Studio 2017

Build .net core project by postbuild event in visual studio 2017

Visual Studio 2017 Community Version Build Project Not Responding

Unable to build My Unit Test Project in Visual Studio 2017

CMake project in Visual Studio 2017 not rebuilding after first build

Xamarin Traditional Android Project Build On Visual Studio 2017 But Have Error

Always run post build event commands in visual studio 2017