compile visual studio solution command line - c

I'm trying to build a VS solution command line, just with the cmd.
I can do it by launching the devenv console, then run devenv command etc... This work, but I have to do it with the cmd, because I use nodejs to run it, and I need to get the output.
Does anybody has a solution ?

As usual with Visual C++, you open a command prompt window using one of "Tools" shortcuts ("VS2015 x64 Native Tools Command Prompt" or others located in C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools\Windows Desktop Command Prompts ).
In this console window, cd to your code and compile. Execute CL or run your makefile or msbuild.
Unfortunately, in VS2015 these shortcuts are more fragile than in previous VS versions, so YMMV.

Related

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?
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.
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. :)

Guys in vs-code how can i run any command on existing terminal without adding new terminal what shortcut-key i can use here?

In visual studio code sometime there is no way to run any command on existing terminal.
So how can i run any command on existing terminal without adding new terminal.
Is there any short-cut key i can use to run any command?
CTRL + SHIFT + P
Its the shortcut to run any command in VS Code

Specifying platform options for Visual studio solution to run cmd in batch

I am running a Xamarin Android project in Visual Studio 2015 from a batch script. I want it to run in release mode (want an APK file created in release mode) and using following code to do so.
"C:\Program Files (x86)\xxx\devenv.com" %SamplesSolutionPath% /run "Release|x86"
But it is running in debug mode and generating APK in debug mode.
Is there a way to insist to run the solution in release mode?

Command Prompt gets open when installing SQL Server using Power Shell

I am using the following code to setup SQL Server using Power Shell
setup.exe /CONFIGURATONFILE=config.ini
When i run the above script in power shell it opens the command prompt and runs the setup.
Is there a way in power shell that the command prompt that is being opened (which i can see on the screen) gets opened in the background.
As because of this command prompt opening i get an error "Requires an interactive shell" when i run the power shell script remotely.
Does it work if you run Setup.exe with the "Silent" mode (No user-interaction) in addition to the ConfigurationFile? Options are documented here : https://msdn.microsoft.com/en-us/library/ms144259.aspx for reference.
Try specifying /Q or /QS
E.g.
".\setup.exe /Q /ConfigurationFile=$commandlineparam"

How to create a Simple Build Script for Visual Studio from the Command Line?

I have a lot of Visual Studio Project Solutions in multiple directories (all with the extension .sln) and I want to write a simple batch script that will automatically build all solutions listed in the batch file.
I am able to manually build a solution by starting up the Visual Studio Command Prompt (which is just a command-line instance with the following command executed
"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
After which I then build the project by calling:
devenv "path\to\solutionFile\projectSolution1.sln" /build Debug
This will build the project (assuming the project does not have errors) and I rinse and repeat for each project I want built.
However when I have the following in a batch file called build.bat:
"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
echo "Starting Build for all Projects with proposed changes"
echo .
devenv "path\to\solutionFile\projectSolution2.sln" /build Debug
devenv "another\path\to\solutionFile\projectSolution3.sln" /build Debug
devenv "yet\another\path\to\solutionFile\projectSolution4.sln" /build Debug
echo "All builds completed."
pause
The batch script only executes the first line, and waits until I type in exit before executing the others. My understanding of this based on the research I have done on batch files and all the StackOverflow questions is that cmd actually invokes another instance of itself that executes vcvarsall.bat to set up the build environment.
This will not work as typing exit kills that instance with devenv set up and the commands after that cannot execute as devenv is not a recognized command (since the exported path will not exist anymore)
In short, how can this be achieved (passing in the rest of the commands to the cmd instance with devenv defined) in a single batch file? I understand this isn't a robust way (and there are a lot of tools that do this) of invoking builds but I'm just hoping to have one batch script to automate the manual work of individually calling these projects.
Found the solution, as noted by Jimmy, one needs to remove the environment variable %comspec% as that is a shortcut to CMD.exe.
However, just removing "%comspec" /k will cause a CMD instance to open and then exit after a second. I also previously tried the call function which created a separate CMD instance when used with %comspec%
The solution is to add call in front of the first line, and remove %comspec
Here is the final batch file that got things working as intended.
#echo OFF
call "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
echo "Starting Build for all Projects with proposed changes"
echo .
devenv "path\to\solutionFile\projectSolution2.sln" /build Debug
devenv "another\path\to\solutionFile\projectSolution3.sln" /build Debug
devenv "yet\another\path\to\solutionFile\projectSolution4.sln" /build Debug
echo .
echo "All builds completed."
pause
Note that #echo OFF tells the batch script to not echo out the commands (such as that call command) into the terminal (errors and warnings will still be shown, however)
If this is already in a batch script, then this line:
"%comspec%" /k "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
Probably should just be "C:\Program Files\Microsoft Visual Studio 10.0\VC\vcvarsall.bat" x86
Why? %comspec% is just an environment variable shortcut to cmd.exe, so as you saw, it's launching a new instance of cmd with the /k option specified (which if you run cmd /? says Carries out the command specified by string but remains). You don't care about it remaining, you don't even want a new cmd.exe when you're already running your batch file.

Resources