Unable to run msbuild for C++ from the command line VS2017 - c++

I have a project that has only ever lived in Visual Studio 2017. It's a C++ dll, and up until this point I've had no problem building it from within the Visual Studio GUI. However now I'm trying to set up automation that will build the project on the command line and upload the output files to a desired location. Here's what I've tried so far (in a brand new Command Prompt):
cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC>
vcvarsall amd64
cd C:\Users\me\development\MyProject
msbuild MyProject.slnl (or msbuild MyProject\MyProject.vcxproj)
And this gives me the error output
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\Microsoft.Cpp.Platform.targets(57,5):
error MSB8020: The build tools for v141 (Platform Toolset = 'v141') cannot be found. To build
using the v141 build tools, please install v141 build tools. Alternatively, you
may upgrade to the current Visual Studio tools by selecting the Project menu or right-cli
ck the solution, and then selecting "Retarget solution".
[C:\Users\dev\development\MetaReme\MetaReme\MetaReme.vcxproj]
Let me reiterate that I've been successfully building within Visual Studio 2017 targeting the v141 toolset, it's just on the command line I'm having trouble. Within my Visual Studio Installer application I have the VC++ 2017 v141 toolset checked. I've looked on the filesystem and within C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\ there is no v141 folder.
Thanks!

Thanks guys! I was following https://learn.microsoft.com/en-us/cpp/build/building-on-the-command-line which says "By default, these tools are installed in drive:\Program Files (x86)\Microsoft Visual Studio version\VC\bin.". Obviously these docs are outdated... I was able to get it to work with the following commands
cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build"
vcvars64
cd "C:\Users\me\development\MyProject"
msbuild MyProject.sln

It says in the first part of the paragraph in the mentioned article:
In Visual Studio 2017, these are located in the VC\Auxiliary\Build subdirectory of the Visual Studio installation directory. In Visual Studio 2015, these are located in the VC, VC\bin, or VC\bin\architectures subdirectories of the installation directory, where architectures is one of the native or cross compiler options.
As you are using Visual Studio 2017, they should be in VC\Auxiliary\Build, like you found out.
Another way to find the correct .bat files would be through the command prompt shortcuts mentioned in the same article. First locate them by expanding start->Visual Studio Year, right click and find their location. Then check the location they are pointing to.

Related

Change Platform Toolset when compiling from CMD

I would like to compile a C++ program via Visual Studio command line tools. I would like to target the executable for 32 bit Windows XP. Tried compiling it the usual way, using x86 Native Tools Command Prompt for VS 2019, but it doesn't work on Windows XP, though runs fine on my Windows 10 machine.
Steps I take:
Open x86 Native Tools Command Prompt for VS 2019.
cd to the project directory. There I'll have 2 folders sources and headers, which shall contain .cpp and .h files respectively.
Execute command cl sources\*.cpp /EHsc /D_WIN32_WINNT=0x050103 /I headers /I <path to boost> /link /libpath <path to boost>\boost_1_77_0\bin\x86\lib\libboost_program_options-vc142-mt-s-x32-1_77.lib /out:exec_xp.exe (the project uses the boost library).
Tried this, but it doesn't work. /D \"_USING_V110_SDK71_\" seems to do nothing, and the /SUBSYSTEM:WINDOWS,5.01 piece isn't recognized by the compiler.
I have learnt from this Microsoft page that we should install deprecated Toolset to compile for WinXP. I went ahead to Visual Studio Installer and installed the C++ Windows XP Support for VS 2017 (v141) tools [Deprecated], as said in the tutorial.
But what now? How can I use this Toolset? I can't find it anywhere on my computer, let alone use it! Visual Studio Installer says it's located under C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools, but it's too vague.
UPD:
Tried with msbuild /p:PlatformToolset=v141_xp, getting this error:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppBuild.targets(439,
5): error MSB8020: The build tools for v141_xp (Platform Toolset = 'v141_xp') cannot be found. To build using the v141_
xp build tools, please install v141_xp build tools. Alternatively, you may upgrade to the current Visual Studio tools
by selecting the Project menu or right-click the solution, and then selecting "Retarget solution"
Which suggests, the compiler doesn't see the v141_xp toolset. I wonder why? It's installed for sure, I did it via the Visual Studio Installer.
I suggest you could try to set the PlatformToolset property:
msbuild myProject.vcxproj /p:PlatformToolset=…
For more details, I suggest you could refer to the Doc:MSBuild command-line reference

Folder "Microsoft Visual Studio 14.0" Is Missing

I'm trying to add pthread library to Visual Studio 2017 (I'm using Windows 10 OS). I'm using the following guide from another post tat I saw, but I can't find the "Microsoft Visual Studio 14.0" folder in "C:\Program Files x86". I have Visual Studio 2017 and It's working. I've checked and I've installed the Visual Studio C++. What else should I install? Is there any other way to include pthread library by just adding it to the project and including the path to the library in the linker or something similar?
Thank you
Since visual studio 2017 visual studio is installed in C:\Program Files (x86)\Microsoft Visual Studio\<version>\<edition> by default e.g. C:\Program Files (x86)\Microsoft Visual Studio\2017\Community. There are other changes to the internal layout of files within the visual studio directory too. Your guide seems to only provide libraries for Visual Studio 2010 and 2012, these won't work in 2017, you should try to find an updated guide (or just use std::thread instead of pthreads).
Installing these files inside the visual studio directory isn't the right approach anyway, install them to a directory of your choice and update your project settings to point to that directory. The lazy approach in the guide is likely to cause problems in the long run.

ATL headers missing when using the VC++ 2015 toolchain on Visual Studio 2017

I am using Visual Studio 2017 for a C++ project (created with VS 2015). I get the following error:
1>C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\afx.h(345): fatal error C1083: Cannot open include file: 'atltrace.h': No such file or directory
How can I install the ATL/MFC headers of the VS 2015 toolchain?
Details
"Platform Toolset" setting (at "Project properties/General/Platform Toolset")
set to "Visual Studio 2015 (v140),
changing the platform toolset to "Visual Studio 2017 (v141) compiles fine.
Files on disc
The include directory for VS 2015 (C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\) contains afx*.h files but no atl*.h files.
These missing files seem to belong to VC_ATL.Headers.msi ("Visual C++ Library ATL Headers Package") (which I checked on another machine with those files). I could not get the respective msi to install. (I took the msi from the other machine.) Error: "To install this product, please run Setup.exe. [...]".
The respective directory for VS 2017 (C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\VC\Tools\MSVC\14.11.25503\atlmfc\include\) does contain those files.
Installer
"Windows Desktop Development with C++/VC++ 2015.3 v140 toolset for desktop (x86,x64)" is checked.
It seems to me that the v140 toolset is missing the ATL/MFC headers.
"Windows Desktop Development with C++/MFC and ATL support(x86 and x64)" does not seem relevant, it seems to be about the VS 2017 version.
VC++ redistributable seems irrelevant since those do not contain the header files.
There is a blog post about the Visual C++ Build Tools 2015. The build tools are also released in a standalone version without the need to install Visual Studio 2015:
The Build Tools are the same C++ tools that you get with Visual Studio 2015 but they come in a scriptable standalone installer that only lays down the tools you need to build C++ projects.
Microsoft has included ATL/MFC.
They can be downloaded from http://landinghub.visualstudio.com/visual-cpp-build-tools. Make sure to select "ATL and MFC" which is deselected by default.

VCVARSALL.BAT for Visual studio 2017

What is the location of file:
VCVARSALL.BAT
for Visual studio 2017?
To summarize, sth along the lines of
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
or
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\vsdevcmd" -arch=x64
(try running it with -help)
My environment:
** Visual Studio 2017 Developer Command Prompt v15.0.26403.7
on Win10 x64
Hans Passant is right.
I had the same problem: no VCVARSALL.BAT for my VS2017 and no Build folder in Microsoft Visual Studio\2017\Community\VC\Auxiliary.
I have Visual Studio Community 2015 and 2017 installed on the same machine.
I didn't have Desktop development with C++ check in my installation. I installed it and the Build folder was created!
Now everything work great.
VS2017 has reworked its directory structure and filenames. You should look for the file 'vcvars.bat', which can be located in "..\Program Files (x86)\Microsoft Visual Studio\2017\EDITION\Common7\Tools\vsdevcmd\ext\vcvars.bat" (replace EDITION with the version of Visual Studio you use).
For simplicity, you can use "%VSAPPIDDIR%" in your call to point to the IDE folder where devenv.exe is located, and go back one folder to define your path to the batch file. For example:
call "%VSAPPIDDIR%..\Tools\vsdevcmd\ext\vcvars.bat"
The VC folder is within the Desktop development with C++ workload. Go to your add or remove programs and modify your Visual Studio 2017, and choose it as shown below:
click on Modify (or Install/Setup in other devices). Go check your folder *\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build* and you'll see the the vcvars64.bat.
I had the same problem - was fixed by removing and reinstalling latest version of microsoft office (2017-2019) resolved the issue. The folder should exist in your MS path automatically, if its not there, uninstall and redownload and install - on my system takes around 3 hours.

Building Visual Studio 2008 solution from command line

I'm trying to automate the building process for a certain open source project. It will do an update on the SVN directory, use CMake to get a .sln file, and build that. I can successfully do this manually, and do svn and cmake from a batch script, but Now I need to build the solution.
A quick google search revealed:
devenv /build release /project <projname> <solutionfile>.sln
However, that uses the latest version of visual studio (Visual Studio Professional 2011), while the .sln file generated is for Visual C++ Express 2008. I have both versions installed on my computer. Is there a devenv I can use for Visual C++ Express 2008? Or is there a commandline argument to specify which version to use?
UPDATE
I tried using msbuild, but that didn't seem to like building .vcproj files directly, and I didn't want to build ALL the project files by having it build the .sln file. I ended up using this:
"C:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages\vcbuild.exe" <myproj>.vcproj "Release|Win32"
I think you are using the wrong tool to build this. Rather than trying to drive the IDE from the command line you should simply use msbuild.
msbuild.exe projectname.proj /property:Configuration=Release
In order to set your environment up for the specific version of MSVC you need to call the vcvar.bat file from that specific version. This will set up the necessary environment variables needed by the build tools.
For Visual Studio Express 2008 the IDE is called VCExpress.exe. Also you should probably specify the full path of the program when you have two versions installed:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\VCExpress.exe /build release /project <projname> <solutionfile>.sln