none
What environment are Pre-Build Events run in? RRS feed

  • Question

  • I have been struggling to get my commands to run as expected for pre-build events. They seem to run just fine in 'cmd' window, but not so much in the VS17. I am specifically trying to startup bash (WSL) to run some remote connection sync and I keep getting errors. I had it all working up until a couple weeks ago when an update broke something. Since then I cannot get it working.
    My latest attempt is to wrap it up in a batch file that I know is working in 'cmd' thinking that VS17 must run in a similar environment.

    DETAILS:
    I know this runs in the 'cmd' window:
    cd d:\Repository & sync_and_deploy_wms.bat

    However, when running this in VS17 on a build I get this (I have on diagnostic mode build output):

    Task "Exec"
        Task Parameter:Command=cd d:\Repository & sync_and_deploy_wms.bat
        cd d:\Repository & sync_and_deploy_wms.bat
        'c:\WINDOWS\System32\bash.exe' is not recognized as an internal or external command,
        operable program or batch file.
        C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.Makefile.Targets(191,5): error MSB3073: The command "cd d:\Repository & sync_and_deploy_wms.bat" exited with code 1.
      Done executing task "Exec" -- FAILED.

    .................
    ..............
    C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Application Type\Linux\1.0\Linux.Makefile.Targets(191,5): error MSB3073: The command "cd d:\Repository & sync_and_deploy_wms.bat" exited with code 1.

    The .bat file is very simple, it just fires up bash and runs a command. Again, this was working for many months before an update came along. Here is the .bat file:
    cd d:\Repository\wms & c:\WINDOWS\System32\bash.exe -l /mnt/d/Repository/wms/remote_sync

    Last time I worked on this it took forever to figure out the "correct" way to setup this command to run in this VS17 environment also, why isn't there more information on the environment that these commands run in? Am I just missing the documentation somewhere??

    Tuesday, March 27, 2018 12:53 PM

All replies

  • Hi,

    Welcome to MSDN forum.

    I will move your thread to Visual Studio Development  >MSBuild forum to discuss the problem. If you have problems about the installation of visual studio, please feel free to let me know.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 28, 2018 6:57 AM
  • Hi TrevorM_,

    Indeed, Visual Studio 2017 should run in a similar environment with batch file, but because their compilers are different (Visual Studio use MSBuild), the scripts that execute them are not exactly the same.

    So to resolve this issue, you can execute the batch file with full path instead of cd in the Pre-build event by following command line:

    call "d:\Repository\sync_and_deploy_wms.bat"

    Just be aware of 2 possible issues you might have:

    1) the enclosing double quotes (see how each part is surrounded by " sign)
    2) if you want to call 2 or more batch files make sure you use call command otherwise you'll have a trouble finding why the second bat is not doing its job.

    I also created a this .bat with test command line in it:

    echo "This is test bat file !"

    After build the project, this bat is executed successfully:


    MSDN Community Support Please remember to click Mark as Answer. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, March 28, 2018 9:04 AM
  • I don't think the issue here is with VS finding/running the bat file. I made the change (using 'call') to start the bat file but I still get the same error:

    call "d:\Repository\sync_and_deploy_wms.bat"
        'c:\WINDOWS\System32\bash.exe' is not recognized as an internal or external command,

    Remember, my bat file starts up bash (WSL) to do a remote sync and 'bash' is not found. Oddly the bat file works fine when running this from 'cmd'.
    Really I would just like to call the bash exe directly from VS17 (which was working previously) but using a bat file for now as a workaround.

    Here is my new command:
    call "d:\Repository\sync_and_deploy_wms.bat"

    Thanks for the help....

    Wednesday, March 28, 2018 1:15 PM
  • @TrevorM_, thanks for your reply. Since I do not have your .bat file, I test it just with a simple bat script "echo "This is test bat file !", it works fine. You can test it. So this error must comes from your .bat file. According to the error info "bash.exe is not recognized as an internal or external command", it seems the bash.exe is not added to the system environment variables, so to resolve this issue, you can try to give the full path of the bash.exe in the cmd file, or add the path of the bash.exe to the system environment variables.

    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, March 28, 2018 1:36 PM
  • The content of the bat file was in the original post:
    cd d:\Repository\wms & c:\WINDOWS\System32\bash.exe -l /mnt/d/Repository/wms/remote_sync

    I am giving it the full path. Why would it work in 'cmd' and not VS? Apparently they have access to different environment.

    About a year ago I was in email contact with Marc Goodner on a related topic and he said:

    .....It should have been a normal cmd prompt with the same environment variables. What it currently is though is a cmd prompt that is initialized with no environment variables. We fixed this, but right now it is scheduled to be in the first 15.4 preview.

    Is this really fixed? Is that my problem?

    I should also mention that I am on v. 15.6.4
    • Edited by TrevorM_ Wednesday, March 28, 2018 2:08 PM
    Wednesday, March 28, 2018 1:50 PM
  • >>>Why would it work in 'cmd' and not VS?

    How did you run it in the cmd? Run this bat file directly in the cmd or just run the content of the bat? It seems you are switch path back and forth when you call this bash.exe in the pre-build event. Have you try to set those file in the same path? Besides, you can contact with Marc Goodner to confirm if this issue if fixed in current Visual Studio.


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 30, 2018 9:18 AM
  • This might not be a problem any more. But I ran into a similar issue. I found out that the Windows UAC settings might cause child processes launching from an admin parent process to be downgraded from the elevated status. This causes the children process to launch without inheriting the environment variables. Change the UAC settings to never notify fixed it for me.
    Monday, October 14, 2019 5:41 PM