'How to run batch file inside Visual Studio 2022 Developer Command Prompt

I recently upgraded to VS2022 I cannot find a way to start developer command prompt and run a batch file inside it. Previously I called vsvars32.bat and it set all variables and paths, allowing me to continue in my .bat file. In the current version it does not work and when I call VsDevCmd.bat, the rest of commands in my batch file are not executed.

Is there a way to call developer command prompt or set paths and variables from batch file and continue?



Solution 1:[1]

I did not find any other solution so ended up using pipe like this:

type cmds.txt | "c:\Program Files\Microsoft Visual

And cmds.txt contains batch file invocation:

buildall.bat

Not pretty, but works.

Solution 2:[2]

I just want to thank you and confirm that this was the only way to automate compilation of a C++ project trhough VS Code.

I tried setting up tasks.json in VS Code and multiple other setups but after 4 days of that nothing worked except your solution PiotrK.

So I ended up preparing a TXT file with a list of commands like so:

set PATH=%PATH%;"C:\Users\DEKOLEV\AppData\Local\Programs\Microsoft VS Code\bin"
cd "C:\path\to\some\folder\with\C++\source\code\files"
code .

}

and I piped the text file directly to the Developer Console link. So now I have a batch file containing the following

type "C:\Some\path\to\file\commands.txt" | "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2022\Visual Studio Tools\VC\x64 Native Tools Command Prompt for VS 2022.lnk"

Starting the batch file starts the x64 developer command prompt and runs VS Code from it which enables VS Code to compile the source C++ files with the environment x64 Native Tools Command Prompt for VS 2022 provides.

I don't have enough points to post a comment so I am posting this feedback as an answer. :)

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 PiotrK
Solution 2 N.K.