command line build for dtproj with targetsqlserverversion - build

Below are the two commands we have configured
For SQL server 2014 :
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" “ \DataLoad.dtproj“ /Rebuild Config2014
For SQL server 2016:
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.exe" “\DataLoad.dtproj“ /Rebuild Config2016
So before configuring these command in to TFS build we ran these commands using command prompt.
When we run this command from command line first command with Config2014 runs successfully.
but for the Config2016 , we get a prompt asking confirmation to proceed further , and after clicking ‘Yes’, this will run successfully and create the ispac file.
Issue :
With the TFS build we need to provide this confirmation using some silent option/switch but so far we did not find any solution to configure this prompt from the command line argument for devenv.exe.
We are looking into using msbuild options rather than devenv but still we don’t get the option for msbuild either to suppress this prompt.

Related

Run cl.exe from cmd

I have installed Visual Studio Community 2017 with C++. I wanted to use its compiler from cmd. I am able to use it from Developer Command Prompt for VS 2017 but I am unable to use it from normal cmd. I have tried running vsvarsall.exe by right click-> run as administrator. But nothing happens. Seems like I have to set environment variables manually.
Whenever I try to run the command
cl hello.c
it says hello.c(1): fatal error C1034: stdio.h: no include path set
Visual Studio includes a batch file that prepares the environment for you (actually, the Developer Command Prompt calls it under-the-hood).
I've never tried with the Community Edition, but for VS 2017 Professional it is located at "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat". It may vary if you changed the installation path, of course.
So, all you have to do is to invoke it:
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat"
Something like following should appear
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.7.3
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'
After that you can invoke cl, nmake, msbuild as within cmd.
You can also invoke vcvarsall.bat x86 instead (the vcvars32.bat is just a shortcut for that).
You can avoid typing it each time by creating a batch that automatically invokes it and then open a command prompt
call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\vcvars32.bat"
cmd
And then run that batch instead of cmd.
Another option is to add the "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\VC\Auxiliary\Build\" to the path so you only have to type vcvars32.bat when you need the developer tools.
Taken from msdn:
A developer command prompt shortcut automatically sets the correct
paths for the compiler and tools, and for any required headers and
libraries. You must set these environment values yourself if you use a
regular Command Prompt window. For more information, see Setting the Path and Environment Variables for Command-Line Builds.
By running vcvarsall.bat in a plain Command Prompt window, you can set environment variables to configure the command line for native 32-bit or 64-bit compilation, or for cross-compilation to x86, x64, or ARM processors.
To run vcvarsall.bat
At the command prompt, change to the Visual C++ installation directory. (The location depends on the system and the Visual Studio installation, but a typical location is C:\Program Files (x86)\Microsoft Visual Studio version\VC\.) For example, enter:
cd "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
To configure this Command Prompt window for 32-bit x86 command-line builds, at the command prompt, enter:
vcvarsall x86
The command file sets the required environment variables for the paths to the build tools, libraries, and headers. You can now use this command prompt window to run the command-line compiler and tools.
If you wish to set the include paths etc. yourself, check out https://learn.microsoft.com/nb-no/cpp/build/reference/cl-environment-variables
open cmd as admin
cd "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\ (check for the correct version of VS)
while in cmd mode, run vcvars64.bat/vcvars32.bat,
now compile ur code for example
cl main.cpp // will give some warning. to supress it type
cl /EHs main.cpp

How can I build all configurations with MSBuild VS2015 from the command line?

In previous versions of MSBUILD you can build all configurations in a solution using the following command line arguments:
msbuild /t:BuildAll /Configuration:"Debug;Release;ContinuousIntegration"
as shown here
However this does not work with MSBUILD VS2015 and gives the following error:
MSBUILD : error MSB1006: Property is not valid.
Switch: Release
This is a similar question to the one here however I am not using cmake just simply straight MSBUILD
For example:
C:\\Program Files (x86)\\MSBuild\\14.0\\Bin\\MSBuild.exe"Uninstaller.vcxproj /property:Configuration=Release'
Sometimes you need run this for setting environment
"C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\vcvarsall.bat"'

How to Run MSBuild Outside of the MSVS Dev Prompt?

I've recently been busy working on making proper build scripts for a code library I've been designing, and have been stuck on getting MSBuild to properly compile for my Windows builds. What I'm trying to do is call MSBuild from a batch script without it opening the Visual Studio IDE, which it appears to constantly do if I'm not executing it from the Developer Command Prompt for Visual Studio. My script is simple enough, just calling
start C:\Program Files (x86)\...\MSBuild\15.0\Bin\MSBuild.exe <Project>.sln
Besides a few other specifiers tagged onto the end of it, that's what I'm trying to use to run my Windows builds. The issue here is that whenever this code is called outside of the VS Dev Prompt, Visual Studio itself opens, not building the code at all. I couldn't find anyone else struggling with this same issue either, as it seems to be new to the integration of MSBuild and Visual Studio. Testing with older versions of MSBuild went to show that I could build projects as I wanted to outside of the Dev Prompt. Could I be missing some environment variable supplied in the Dev Prompt that changes the executable behavior? I couldn't seem to find any executable specifiers that would change this, either.
Maybe I'm taking a completely wrong approach to this problem? My end goal is to provide consumers with a collection of build scripts, one for each platform they're targeting, so I am definitely open to other solutions.
The canonical answer:
You can use the devenv command with the /build command line option and the name of your project file.
Alternatively, you can run one of the vcvars*.bat scripts to set up the necessary environment and then use msbuild.
For more info, see https://learn.microsoft.com/en-gb/cpp/build/building-on-the-command-line.
Update: Contrary to the official advice above, this is what works on my laptop with VS2017 community edition.
Setup the environment by running the bat file that is targeted by the "developer command prompt for VS2017". (Right-click on that in the start menu, then select "Open file location" then right-click on the shortcut and select "properties". For me that is "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat".
You should call this file from your build script.
cd to your project directory and then use msbuild like this:
msbuild My-project.vcxproj /p:Configuration=Release
For some really strange reason I can use the devenv method if I open the official developer command prompt but launching devenv from another command prompt even with the environment variables set does nothing. (And I even compared the set of environment variables in both command prompts and they are equal.)
How to Run MSBuild Outside of the MSVS Dev Prompt?
If the necessary environment not be set correct, then the build command becomes " mysolution.sln". And executing it indeed starts VS. So you should run the vcvars*.bat scripts to set up the necessary environment and then use msbuild. Following is my a batch script, it has been working for some time, you can check it:
#echo OFF
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
echo "Starting Build for all Projects with proposed changes"
MSBuild.exe "C:\Users\Admin\Source\repos\MyTestProject\MyTestProject.sln"
pause
echo "All builds completed."
Here is the test sample result:
See How to create a Simple Build Script for Visual Studio from the Command Line? for more details.

How to build a QT-project in visual studio from command line

I am trying to automate the build process for one of my QT-project. I used the following command in my batch file for non-QT projects
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" "myproject.sln" /build "Debug|x64" /projectconfig Debug
but it is not working for my QT project. Am I missing something?
Here is an example on how to do that (command by command):
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
cd <my_project_directory>
qmake
nmake
The first command sets up the environment for using Visual Studio tools.
Second command changes the current directory to one where your Qt project file is (you have to have one).
Third command runs Qt's qmake.exe utility to generate make files.
And finally nmake will build your project.
However, if you don't use Qt project files and have only VisualStudio solution, you can use MSBuild utility, like:
"C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\vcvarsall.bat" x86
MSBuild your_solution.sln /p:Configuration=Debug
You can also set additional environment variables, such as QTDIR if it does not find your Qt installation.
If somebody finds this question looking for an answer on how to automate the build process of a QT project, and wants to do it using a BATCH file as the original question states, here is the BATCH script that I used to automate my building process:
#echo off
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
cd %path_to_your_repo%
nmake /f Makefile.Release clean && qmake.exe %path_to_your_.pro% -spec win32-msvc "CONFIG+=qtquickcompiler"
nmake qmake_all
nmake -f Makefile.Release
It is important to call the vcvarsall.bat the first thing, as this will set the environment for all visual studio tools. Also make sure to launch it with call, if you just start the batch file as in #vahancho's answer it will stop your script after executing vcvarsall.bat.
The clean step is not necessary but it is a good practice to use it before building.
It is important to select the -spec and CONFIG (if any) during the qmake step, as this will allow you to select the compiler and required configuration if you are using some extra QT configuration.

How Can Be Used the Command Line of Developer Command Prompt in Vim on Windows?

I have Visual Studio Express for Windows Desktop installed on this laptop and I can compile a C++ source file with the command cl /EHsc filename.cpp and a C++ program that uses .NET classes with the command cl /clr filenameclr.cpp on the command line of Developer Command Prompt for VS2012 using this instructions: http://msdn.microsoft.com/en-us/library/ms235639.aspx
How can I be able to compile in Vim (text editor) on Microsoft Windows with those commands? :cl /EHsc filename.cpp and :cl /clr filenameclr.cpp does not work.
You need to setup your PATH, INCLUDE and LIB environment variables.
You could do that by running D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat (or wherever it is located on your installation) in the same prompt you're running vim, or even manually setting these environment variables (here is a list of all values for VS2008 and Windows SDK: Using Visual Studio's 'cl' from a normal command line).
However, you just can't run the bat file from vim directly, because it will open another Prompt, so the environment variables will be set only for that new prompt. The other option is just to create bat file which you can put it inside your PATH, for example cvim:
call "D:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
"C:\Program Files (x86)\Vim\vim74\gvim.exe"
After that, typing cvim.bat will get you in the environment ready for running :! cl /EHsc %