vsvars32.bat in Visual Studio 2017 - visual-studio-2017

As the Visual Studio installer is new from Visual Studio 2017 version, I cannot located the Visual C++ component, explained here.
How do I proceed to get the vsvars32.bat in VS2017?

VS2017 suffers from very seriously brain-damaged install path location choices. Most damning dumb thing they did is to make the edition name (Professional, Enterprise, probably Community) part of the path. This makes it quite difficult to find tools back reliably from one machine to another.
There is one environment variable that I think can solve the problem, the VSAPPIDDIR variable stores the path to the folder where the IDE is installed (devenv.exe). So if you want to run vcvars32.bat from a build event then you'd use
call "%vsappiddir%..\..\VC\Auxiliary\Build\vcvars32.bat" x86
Note that it is vc, not vs, vsvars32.bat no longer exists. You could possibly favor the "Developer Command Prompt:
call "%vsappiddir%..\tools\vsdevcmd.bat"
But judging from your link, you actually want to run the editbin.exe utility:
"%vsappiddir%..\..\VC\Tools\MSVC\14.10.25017\bin\HostX86\x86\editbin.exe" args...
The 14.10.25017 version number is no joy whatsoever either, no real insight in how that is going to change from one update to the next. It probably will.

I know the question is (well) answered, but I would like to share how I solved the problem hoping it will help people googling for a solution
#echo off
set INSTALLPATH=
if exist "%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
for /F "tokens=* USEBACKQ" %%F in (`"%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15.0 -property installationPath`) do set INSTALLPATH=%%F
)
echo INSTALLPATH is "%INSTALLPATH%"
REM Save current dir for later
pushd %CD%
if NOT "" == "%INSTALLPATH%" (
call "%INSTALLPATH%\Common7\Tools\VsDevCmd.bat"
) else (
goto ERROR_NO_VS15
)
:WORK
REM Retrieve the working dir and proceed
popd
echo Doing work in %CD%
svcutil this_is_just_an_example
goto END
:ERROR_NO_VS15
echo Visual Studio 2017 Tools Not Available!
:END
echo Processing ends.
A small explanation of the above script.
vswhere.exe is a single-file, native executable you can download or redistribute with your build and deployment environments to locate Visual Studio or other products installed with the new installer for Visual Studio 2017 (from the vswhere wiki)
Starting with Visual Studio 15.2 (26418.1 Preview) vswhere.exe is installed in %ProgramFiles(x86)%\Microsoft Visual Studio\Installer (use %ProgramFiles% in a 32-bit program prior to Windows 10). This is a fixed location that will be maintained (as noted here)
This allows developers to query for several important features of a Visual Studio 2017 (and above) installation. Furthermore, the tool was designed to allow different flavors of Visual Studio (Community Edition, Professional, ...) to be installed on the same machine.
You can find several usage examples here.
As for the script, the first relevant part
if exist "%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" (
for /F "tokens=* USEBACKQ" %%F in (`"%programfiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -version 15.0 -property installationPath`) do set INSTALLPATH=%%F
)
Queries vswhere for the installation Path of Visual Studio 2017 (-version 15.0) and sets a variable named INSTALLPATH.
It should be noted that on a 32 bits OS, you should use %programfiles% instead of %programfiles(x86)%.
Due to this issue, the script saves the current directory for later retrieval.
The script then proceeds to test the contents of the INSTALLPATH variable. If the variable is not empty, it appends "Common7\Tools\VsDevCmd.bat" to it (which is a well known relative path where one can find development tools for the corresponding Visual Studio installation). Otherwise, the script jumps to an error message and exits (you may opt to return a non-zero error code).
If all went well, you have now a full fledge Visual Studio development environment at your disposal.
The script now proceeds to retrieve the original directory and execute something, in this case a dummy call to svcutil.

Just change "vsvars32.bat" to "vsdevcmd.bat". This is compatible at least back to VS2015.
call "$(DevEnvDir)..\tools\vsdevcmd.bat"
editbin /largeaddressaware "$(TargetPath)"

Microsoft changes the vcvars32.bat to VsDevCmd.bat in VS 2017 link
I use vcvars32.bat in pré-build (project properties->build events), so for me, I've changed:
"$(DevEnvDir)..\..\VC\bin\vcvars32.bat"
to
$(DevEnvDir)\..\Tools\VsDevCmd.bat"
and it worked!
Edit:
In Visual Studio 15.9 the path was changed (as Fütemire said
in the comment), so I had to change:
$(DevEnvDir)\..\Tools\VsDevCmd.bat"
to:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat
*You can create an environment variable to store the path. I couldn't find an already defined.

None of the mentioned solutions worked for me. After getting my head warmed up from the "vsvars32.bat missing" error - I went through every single line and there was too 'svcutil.exe' was missing.
I thought of fixing that and it worked. I got the following path in my machine for SvcUtil.exe:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin
I set the path in System Environment Variable and restarted my Visual Studio for just in case and it worked.
Hope this helps someone!
Edit:
Very Strange - it works when I have "Lightweight solution load" enabled. As soon I'ml disabling "Lightweight Solution Load" - it starts giving me same error!

In Visual Studio 2017 (inkl. C++ Build Tools installed) I do it in this manner in the post build events to check also for x86:
if not $(PlatformName) == x64 (
if exist "$(DevEnvDir)..\tools\vsdevcmd.bat" (
echo setting largeaddressaware to get 4gb access in 32 bit
call "$(DevEnvDir)..\tools\vsdevcmd.bat"
editbin /largeaddressaware "$(TargetPath)"
)
)

Related

How to solve " 'cl' is not recognized as an internal or external command" issue in visual studio 2017 community edition?

I am trying to follow examples from Gray Hat Hacking where 32 bit C programs are compiled in visual studio. My issue is that visual studio 2017 developer prompt opens with errors like the following
'type "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.isolation.ini"' is not recognized as an internal or external command,
operable program or batch file.
**********************************************************************
** Visual Studio 2017 Developer Command Prompt v15.0
** Copyright (c) 2017 Microsoft Corporation
**********************************************************************
'dir "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\vsdevcmd\ext\*.bat" /b /a-d-h /on' is not recognized as an internal or external command,
operable program or batch file.
I also understand that I may have to add the location of cl in the environment variables and I may have to run the vcvarsall.bat file. I tried all these with no significant progress.
My objective is to compile and run 32 bit as well as 64 bit C programs on my 64 bit platform on visual studio. I would appreciate if anyone could help me with this issue.
For anyone who is running into the same problem, that I encountered. I found a solution to this problem, but I have no guarantee that this would work for everyone.
I must admit, configuring visual studio to run C programs is one heck of a job!!! One would go nuts trying to set up the right environment variables for a smooth execution of a C program. Once you install visual studio with the Build tools, the right SDKs (preferably the latest ones) and the latest VC++ toolset, the following environment variables will have to be set:
LIB
INCLUDE
PATH
Set these environment variables for both system and user (to be on the safe side) and if any file is missing, find its location (Most likely, their location would be in Windows Kits or somewhere within the Visual Studio folder. Expect some hunting!!!), then try to compile until it becomes successful.
If any one else has a better solution, I would request them to post it here!!!

Visual Studio: copy installation folder and setup it up to be auto-detected by Qt Creator

I wiped out an old Windows 10 and replaced it with a new Windows 10 by ISO image.
Before wiping out, I copied the folder of Microsoft Visual Studio 2017 Community Edition on old Windows to an external hard disk:
xcopy /E "C:\Program Files (x86)\Microsoft Visual Studio" D:\
Now after reinstalling Windows 10, I copied the VS 2017 folder from external the hard disk to the C:\Program Files (x86)\ folder of new operating system.
I did so to avoid having to download VS 2017 again on new OS.
The problem is other software, like Qt Creator, cannot auto-detect the VS C/C++ compilers. I guess that's because the VS 2017 isn't added to path.
The questions are:
What path should I add to system path in order to VS 2017 to be auto-detected by other software like Qt Creator?
Is there any script which I can run to automatically integrate the VS 2017 to the rest of the operating system.
To answer the questions in your issue:
Copying the content of C:\Program Files (x86)\Microsoft Visual Studio folder is not a recommended way to install VS.
(The complete installation will not only set the Environment variables but also set the related registry keys and values. A simple copy may break this process)
So we always suggest that users install the VS by vs-installer or offline installation package. (Same like what Zlatomir suggests.)
To your actual requirements:
It seems you're just trying to use VC++ compiler in QT Creator instead of developing QT projects in Visual Studio. So build tools for VS package is enough for you.
See this related issue, if we download Build Tools for VS package with corresponding C++ workload, then we can get the compiler the QT needs. There's no need to install the VS IDE for this situation.
And if we need C++ compiler from VS2017, download the Build Tools for VS2017, if we need C++ compiler from VS2015, download the Build Tools for VS2015 Update3. Link of old version about VS Tools see here.
Update:
From the the link older downloads we can see:
Choose the download button according to which version we need. We can find both VS2017 build tools package and VS2015's there.
Usually programs on Windows don't work after you just copy the installation folder.
So right now there is little you can do to fix it, even if you partially fix, you have no way to know if something else will be broken in the future.
So the recommended solution is to download the installer again and create an offline installer for the next time this happens, you can do that by running the online installer with the following parameters: vs_community.exe --layout c:\vslayout --lang en-US (replace vs_community.exe with the actual name of the online installer file, or rename it), for more options, that might require a smaller download (example if you only need native and don't need .net) check the documentation here for the full set of options you have.

Emacs key bindings in Visual Studio 2017

I'm trying to get Emacs style key bindings in VS 2017.
From the Q&As related to previous - VS - versions, I tried:
The VS settings (Tools->Options->Environment->Keyboard), but there is no Emacs option: apparently it was removed starting with VS 2010;
XKeymacs (though it seems antique, who knows?), but it only supports windows versions up to Vista and I'm running on windows 8;
VisEmacs, but it supports VS up to version 2008;
Downloaded the VS 2010 extension, extracted from archive, modified version (see note below for how I retrieved it), re-archived and ran it with the VSIXInstaller as explained in this answer.
However, after I selected the Emacs option in the VS Keyboard mappings, and after several restarts, not only do the Emacs key bindings fail to work, but also the previous kbd mappings were disabled, even the common ones like Ctrl+arrows. I checked and the commands are there, they just don't work.
So here is where I got stuck.
N.B. In order to find the VS version:
C:\Program Files (x86)\Microsoft Visual Studio\Installer>vswhere.exe
Visual Studio Locator version 1.0.62 [query version 1.10.80.60812]
Copyright (C) Microsoft Corporation. All rights reserved.
installationName: VisualStudio/15.2.0+26430.16
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
installationVersion: 15.0.26430.16
Tried with 15.2 and 15. (and 17 and 16 and 15.3, prior to that :) )
P.S. It seems like this question was asked for every VS version... This could be a hint for the VS team :).
Tools -> Extensions and Updates -> (search Online) Emacs Emulation
I've had to do this setup myself a number of times and thought I would try my hand at the 2017 variety so here it goes!
I followed the general instructions listed in other solutions here and here.
The extension.vsixmanifest has the following entries (only relevant section shown):
<SupportedProducts>
<VisualStudio Version="15.0">
<Edition>Pro</Edition>
</VisualStudio>
<VisualStudio Version="14.0">
<Edition>Pro</Edition>
</VisualStudio>
</SupportedProducts>
Version 15 will work with VS Community 2017. Edition should be Pro as there's no difference like there was in previous Express varieties.
Note that when you build the zip file, you need to do it such that the vsixmanifest, the dll, the pkgdef, etc. are all contained in the root of the zip. This means you shouldn't zip the EmacsEmulation folder, rather zip the contents from inside the folder.
I then opened up an administrator command prompt to install the file. Visual Studio 2017 was closed when I did this. I have my installation in the default folders.
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\ide\VSIXInstaller.exe" /a EmacsEmulation.vsix
Note I saw a bunch of warnings about this extension messing up VS 2017. Against all warnings I kept opting to install the extension.
Warning: The warnings about the extension being potentially incompatible with VS 2017 weren't far off. I was happy to see the key map was available when I opened Tools -> Options ... Environment / Keyboard but when I went to my code I couldn't get it to go to the beginning or end of line. I had to remove the keyboard shortcut for Editor Select All and restart VS before it worked properly. There may be other caveats to using this extension so YMMV.
Side note: I took my version that worked with 2015 and just added the version 15 to the XML. It seems to be "fine".

Building Boost - can't find windows.h

I'm trying to build boost on windows 7 64-bits. Running bootstrap gives
execnt.c(29) : fatal error C1083: Cannot open include file: 'windows.h': No such file or directory
and some others. I have visual studio 9.0 and the places where I have windows.h is in
C:\Program Files (x86)\Microsoft SDKs\Windows\v5.0\Include**W**indows.h, with capital W
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include**W**indows.h
C:\Program Files (x86)\Microsoft Visual Studio 9.0\SmartDevices\SDK\Smartphone2003\Include\windows.h
I have the SDK installed and even fully reinstalled Visual studio. Any way I can fix this?
Small update: I installed Visual C++ 2010 express and from the IDE I can include and the test project compiles just fine, but when I use the prompt NO projects can find the header
Try running the boost build from a VS console rather than trying to run 'cmd'. It's probably somewhere in the start menu entry for VS (used to be anyway). It used to also be available from VS itself under tools, but I think they removed it there.
This version is just cmd, but it runs a batch script that sets a bunch of very important environment variables.
For future reference of anyone looking for the same error
I have installed visual studio without registry edition permission, so I had none of the environment variables set, those that boost libraries / libxml2 et al look for when calling the cl compiler
Giving myself permission to edit the registry and uninstalling/reinstalling all visual studio related programs solved it
Edit %VS90COMNTOOLS%vsvars32.bat with administrator privileges any way you like, eg.
runas /user:Administrator "notepad %VS90COMNTOOLS%vsvars32.bat"
Find the section
:GetWindowsSdkDirHelper
#for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows" /v "CurrentInstallFolder"') DO (
if "%%i"=="CurrentInstallFolder" (
Change it to
:GetWindowsSdkDirHelper
#for /F "tokens=1,2*" %%i in ('reg query "%1\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v6.0a" /v "InstallationFolder"') DO (
if "%%i"=="InstallationFolder" (
When you install a newer version of the Windows SDK, it updates HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\CurrentInstallFolder to point to the newer version.
Unfortunately, the batch file that Visual Studio 2008 uses to set its paths uses this registry key to identify the location of the Windows SDK, so instead of pointing at the version of the Windows SDK that works with VS2008 (6.0a), it points to the the latest version to be installed.
Editing the registry is one option. A better option is to change the batch file so that it gets the right path from the registry, as above.

'cl' is not recognized as an internal or external command,

I am trying to compile a hello world program in Qt Using Qt Creator.
I am getting 'cl' is not recognized as an internal or external command.
I am using Windows 7 and both VS 2008 and 2010 installed in it.
When I use Mingw it is compiling fine but if use vs 2008 it is giving this error.
After Setting Env Path = ..;..;C:\Program Files\Microsoft Visual Studio 9.0\VC\bin also it is showing the same error.
That error happens because cl isn't in your path. You need to add it there. The recommended way to do this is to launch a developer command prompt.
Quoting the article Use the Microsoft C++ toolset from the command line:
On the desktop, open the Windows Start menu. In Windows 11, choose the All apps button to open the list of installed apps. In Windows 10,
the list is open to the left. Scroll down the list to find and open
the folder (not the app) for your version of Visual Studio, for
example, Visual Studio 2022.
In the folder, choose the Developer Command Prompt for your version of Visual Studio. This shortcut starts a developer command
prompt window that uses the default build architecture of 32-bit,
x86-native tools to build 32-bit, x86-native code. If you prefer a
non-default build architecture, choose one of the native or cross
tools command prompts to specify the host and target architecture.
For an even faster way to open a developer command prompt, enter
developer command prompt in the desktop search box. Then choose the
result you want.
As the article notes, there are several different shortcuts for setting up different toolsets - you need to pick the suitable one.
If you already have a plain Command Prompt window open, you can run the batch file vcvarsall.bat with the appropriate argument to set up the environment variables. Quoting the same article:
At the command prompt, use the CD command to change to the Visual Studio installation directory. Then, use CD again to change to the
subdirectory that contains the configuration-specific command files.
For Visual Studio 2019 and Visual Studio 2017, use the
VC\Auxiliary\Build subdirectory. For Visual Studio 2015, use the VC
subdirectory.
Enter the command for your preferred developer environment. For example, to build ARM code for UWP on a 64-bit platform, using the
latest Windows SDK and Visual Studio compiler toolset, use this
command line:
vcvarsall.bat amd64_arm uwp
From the article, the possible values for the first argument are the following:
x86 (x86 32-bit native)
x86_amd64 or x86_x64 (x64 on x86 cross)
x86_arm (ARM on x86 cross)
x86_arm64 (ARM64 on x86 cross)
amd64 or x64 (x64 64-bit native)
amd64_x86 or x64_x86 (x86 on x64 cross)
amd64_arm or x64_arm (ARM on x64 cross)
amd64_arm64 or x64_arm64 (ARM64 on x64 cross)
I had the same problem.
Try to make a bat-file to start the Qt Creator. Add something like this to the bat-file:
call "C:\Program Files\Microsoft Visual Studio 9.0\VC\bin\vcvars32.bat"
"C:\QTsdk\qtcreator\bin\qtcreator"
Now I can compile and get:
jom 1.0.8 - empower your cores
11:10:08: The process "C:\QTsdk\qtcreator\bin\jom.exe" exited normally.
Make sure you restart your computer after you install the Build Tools.
This was what was causing the error for me.
I had the same problem and I solved it by switching to MinGW from MSVC2010.
Select the Project Tab from your left pane. Then select the "Target". From there change Qt version to MinGW instead of VC++.
You will have to set environmental variables properly for each compiler. There are commands on your Program menu for each compiler that does that, while opening a command prompt.
Another option is of course to use the IDE for building your application.
I had this problem because I forgot to select "Visual C++" when I was installing Visual Studio.
To add it, see: https://stackoverflow.com/a/31568246/1054322
I had the same issue for a long time and I spent God knows how much on it until I accidentally figured what to do. This solution worked on windows 10. All you need to do is to add C:\WINDOWS\System32 to Path variable under User Variables in Environmental Variables... Note that if you add this to the system variables, it may also work. But, that didn't work for me.
You can use Command prompt for VS 2010 and then select the path that your boost located. Use "bootstrap.bat", you can successfully install it.
For me, this was related to the scenario described by Smi, with the difference being that vcvarsall.bat itself was failing due to an invalid path.
This was cause by line-breaks within the path, which meant vcvarsall.bat couldn't find the common tools directory for some reason.
I sometimes get this problem when changing from Debug to Release or vice-versa. Closing and reopening QtCreator and building again solves the problem for me.
Qt Creator 2.8.1; Qt 5.1.1 (MSVC2010, 32bit)
I faced this error too, checked that there are multiple versions of common tool variables for visual studio in my environment variables (VS120COMNTOOLS, VS110COMNTOOLS and so on) for different visual studio versions.
I removed the ones I did not need from the environmental variables and the issue was resolved.
I was facing the same issue and tried many solutions but nothing work ( I was using vscode 2017) . I just upgraded vscode to 2022 version and the problem is automatically