vsvars32.bat in Visual Studio 2017

后端 未结 6 434
南笙
南笙 2020-12-08 13:31

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

相关标签:
6条回答
  • 2020-12-08 13:41

    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.

    0 讨论(0)
  • 2020-12-08 13:47

    Just change "vsvars32.bat" to "vsdevcmd.bat". This is compatible at least back to VS2015.

    call "$(DevEnvDir)..\tools\vsdevcmd.bat"
    editbin /largeaddressaware "$(TargetPath)"
    
    0 讨论(0)
  • 2020-12-08 13:49

    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!

    0 讨论(0)
  • 2020-12-08 13:50

    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.

    0 讨论(0)
  • 2020-12-08 13:50

    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)"
    )
    )
    
    0 讨论(0)
  • 2020-12-08 14:03

    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.

    0 讨论(0)
提交回复
热议问题