Skip to content

Instantly share code, notes, and snippets.

@flying-tiger
Last active June 15, 2022 23:08
Show Gist options
  • Save flying-tiger/69efb062002edd3226777f8187ffcfc7 to your computer and use it in GitHub Desktop.
Save flying-tiger/69efb062002edd3226777f8187ffcfc7 to your computer and use it in GitHub Desktop.
VS Command Line Tools in WSL

Starting with the Windows 10 Creators update, Windows will append the Windows application search path to Bash's PATH variable on startup. This allows Windows applications to be called from the Linux shell like any other program (see this blog post for details).

Here's my favorite part about this: with this update, if you start Bash from within the Visual Studio Developer Command Prompt, you will have command line access to all the Visual Studio tools. This enables some neat opportunities like calling cl.exe from a makefile to build software. I prefer working on the command line and I'm not a fan of cmd.exe or Powershell, so this is a great way to leverage the native Windows toolchain from the comfort of a Linux shell.

To create a shortcut that will automatically start Bash using the VS command prompt, use the following as the shortcut target:

%comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsDevCmd.bat" && "C:\Windows\System32\bash.exe" ~"

After launching via this shortcut, executing devenv.exe /? should open a help window. However, see that error you just got?

Unable to translate current working directory. Using C:\WINDOWS\system32.

There is one catch to all this: the Linux filesystem should not be modified using Windows apps and tools. As such, executing the VS tools from a location on the Linux filesystem will cause errors. So if you want to use these tools from Bash, be sure to work from a directory on the Windows filesystem (/mnt/c/Users/...). In my case, I just keep all my projects on the Windows side an put a symlink in my Linux home directory so I can get there quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment