Kicking off a WSL bash-based build from Visual Studio 2015
Asked Answered
F

2

5

I recently started using the Windows Subsystem for Linux (WSL) to see if my Linux Makefile & arm-none-eabi-gcc based microcontroller project would build "natively" in Windows. To my surprise, the tool chain and Linux based development tools installed and worked perfectly on first go, without any modifications to the Makefile.

So that got me thinking to try doing all my code editing in Visual Studio using the IDE features while doing the actual build in the Linux & bash environment provided in WSL.

Unfortunately, when specifying a "Build Command Line" in the NMake options for my Visual Studio project, putting in "C:\Windows\System32\bash.exe build.sh" doesn't work because:

'C:\Windows\System32\bash.exe' is not recognized as an internal or external command, operable program or batch file.

This is strange to me because I specified the full path and it couldn't find the WSL bash executable, and also attempting to add it as an "External Tool" doesn't seem to work because the executable doesn't show up in the selection window despite being able to see other executables in the same directory.

Some off topic opinion: If Microsoft can make Visual Studio and WSL work together seamlessly then I would likely switch from my Ubuntu virtual machine setup for a WSL based development environment.

Fist answered 6/7, 2016 at 18:45 Comment(7)
Possible duplicate of Windows Bash and Visual Studio Code: How can I launch bash as a run task?Jarrodjarrow
Not a duplicate – "Visual Studio Code" is a completely different program from "Visual Studio". The answer about using C:\Windows\sysnative\bash.exe as the path is interesting, but still doesn't work for me.Encounter
@Fist did you ever find a solution?Encounter
@Encounter I have not found a solution yet, but have not tried any of the suggestions in that post yet. Curious, when copied to 'sysnative' did you mean C:\Windows\SysWOW64? Because it looks like one of the users in the other post had success with that.Fist
"sysnative" is magic. 64-bit binaries live in System32. 32-bit binaries live in SysWOW64. When a 32-bit exe runs and tries to open System32, it silently gets handed SysWOW64 instead. So, if you use the path "sysnative" a 32-bit exe can open the real System32 folder. (So, there’s no copying files involved)Encounter
It sort of worked for me – I no longer get "is not recognized as an internal or external command…", and instead just get "cmd.exe exited with code -1", and no output from bash at all. Even simple echo commands. Pretty stuck now.Encounter
so any fix? I'm having these problems too, no output, -1Religious
C
1

Here's how you have to do it:

Nmake is not a 64-bit application, so when it tries to use Windows utilities and system32, WoW64 tricks it into looking in a different location.

The way you have to launch it from a 32-bit application is:

%windir%\sysnative\bash.exe

However, your command is also malformed. You will need to do it like this:

%windir%\sysnative\bash.exe -c "sh build.sh"

or maybe

%windir%\sysnative\bash.exe -c "./build.sh"

if DriveFS permissions allow execution.

otherwise it will attempt to execute build.sh as a command in your linux user's $PATH.

Source: https://github.com/Microsoft/BashOnWindows/issues/870

Clabber answered 30/8, 2016 at 9:35 Comment(0)
R
0

This is what I have in my Build Command Line setting. It works fine.

start /WAIT %windir%\sysnative\bash.exe -c "cd /mnt/d/Projects/IoT/ESP8266/;./gen.sh -m DEBUG; read -n 1; exit;"
Ruthi answered 8/8, 2018 at 19:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.