首页 > 其他 > 详细

获取VisualStudio命令行脚本路径(VS2019、VS2017、VS2015)

时间:2020-11-17 17:24:25      阅读:166      评论:0      收藏:0      [点我收藏+]

GetVisualStudioEnvScript.bat

@echo off
setlocal enabledelayedexpansion

call :GetVisualStudioEnvScript devenv
if not "!devenv!" == "" (
    echo devenv="!devenv!"
)

pause

::获取字符串长度
::%1 string
::%2 len
:StrLen
    setlocal enabledelayedexpansion
    set len=0
    set str=%~1

:StrLenLoop 
    if not "!str:~%len%!"=="" (
        set /A len+=1
        goto :StrLenLoop
    )
    (endlocal & set %2=%len%)
    goto :eof

::查找字符串
::%1 string
::%2 token
::%3 pos
:StrFind
    setlocal enabledelayedexpansion
    set "pos=0"
    call :Strlen %2 len
    set "str=%~1"
    set "token=%~2"
    ::echo str=%str% token=%token%
:StrFindLoop
    if not "!str:~%pos%,%len%!"=="!token!" (
        set /A pos+=1
        goto :StrFindLoop
    )
    if "!str:~%pos%,%len%!"=="!token!" (
        (endlocal & set %3=%pos%)
    ) else (
        (endlocal & set %3=-1)
    )
goto :eof

::获取VisualStudio脚本
::%1 devenv
:GetVisualStudioEnvScript
    setlocal enabledelayedexpansion
    for /f "Delims=" %%i in (REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe") do (
        set "value=%%i"
        set "value=!value:*reg_sz=!"
        for /f "tokens=*" %%b in ("!value!") do set devenv=%%~fb
    )

    ::echo devenv="%devenv%"

    call :StrFind "%devenv%" "Common7\IDE\devenv.exe" dirpos
    if %dirpos% == -1 (
        echo Visual Studio Version Unknown : "%devenv%"
        set "devenv="
        goto GetVisualStudioEnvScriptEnd
    )

    call :StrFind "%devenv%" "2019" pos
    if not %pos% == -1 (
        set "devenv=!devenv:~0,%dirpos%!VC\Auxiliary\Build\vcvarsall.bat"
        goto GetVisualStudioEnvScriptEnd
    )

    call :StrFind "%devenv%" "2017" pos
    if not %pos% == -1 (
        set "devenv=!devenv:~0,%dirpos%!VC\Auxiliary\Build\vcvarsall.bat"
        goto GetVisualStudioEnvScriptEnd
    )

    call :StrFind "%devenv%" "Microsoft Visual Studio 14.0" pos
    if not %pos% == -1 (
        set "devenv=!devenv:~0,%dirpos%!VC\vcvarsall.bat""
        goto GetVisualStudioEnvScriptEnd
    )
    set "devenv="
:GetVisualStudioEnvScriptEnd
    ::echo devenv="!devenv!"
    (endlocal & set "%1=%devenv%")
goto :eof

输出:

技术分享图片

 

获取VisualStudio命令行脚本路径(VS2019、VS2017、VS2015)

原文:https://www.cnblogs.com/dongc/p/13995032.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!