'How to run devenv.exe command line switches (for Visual Studio 2019) from git bash

My primary use case is I'd like to use devenv.exe /edit command to open files in an already running instance of Visual Studio 2019, using git bash.

The issue I'm having is that I cannot seem to finesse git bash to run the command in a way that actually works.

Specifically, this is what I'm seeing:

from windows cmd:

  • command: devenv /edit foobar.c
  • results: SUCCESS!; opens foobar.c in an existing instance of visual studio 2019

from git bash:

  • command: devenv /edit foobar.c
  • result: FAIL!; opens a new instance of 2019, and has an error popup saying: The following files were specified on the command line: "C:/Program Files/Git/edit" These files could not be found and will not be loaded. Opens file

from git bash, tucking the command under a .bat file

  • mybat.bat contents: devenv /edit foobar.c
  • command: cmd //c mybat.bat
  • result: FAIL!; Opens a new instance of 2019, no error popup, opens file.

from git bash, using full paths to exe and file

  • command: "/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/devenv.exe" /edit /c/Users/MYNAME/foobar.c
  • result: FAIL!; opens a new instance of 2019, and has an error popup saying: The following files were specified on the command line: "C:/Program Files/Git/edit" These files could not be found and will not be loaded. Opens file

from git bash, escaping the edit command and and using full paths:

  • command: "/c/Program Files (x86)/Microsoft Visual Studio/2019/Professional/Common7/IDE/devenv.exe" /edit /c/Users/MYNAME/foobar.c
  • result: FAIL!; Opens a new instance of 2019, no error popup, opens file.

from git bash, after opening the sln via git bash:

  • command 1: devenv.exe my_solution.sln &
  • result: Opens my solution
  • command 2: devenv.exe //edit foobar.c &
  • result: SUCCESS!; opens foobar.c in an existing instance of visual studio 2019
  • Command 3 (from a different git bash): devenv //edit foobar.c &
  • result: FAIL!; Opens a new instance of 2019, no error popup, opens file.

Can anyone think of a method to invoke the command from git bash, in the same fashion that a windows command prompt (cmd.exe) would invoke the command?



Solution 1:[1]

The only solution I could find was to put "& "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe" "solution.sln" /Build Release in a .ps1 file and call powershell build.ps1 from my .sh file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tschumann