Kicking off a WSL bash-based build from Visual Stu

2019-01-26 13:47发布

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.

2条回答
相关推荐>>
2楼-- · 2019-01-26 14:13

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

查看更多
家丑人穷心不美
3楼-- · 2019-01-26 14:17

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;"
查看更多
登录 后发表回答