我以不同的方式解决了这个问题。我在 Windows worker 上安装了一个批处理文件,它在启动时调用环境设置批处理文件,然后执行预期的命令。当然,由于批处理文件在转发参数方面很糟糕,而且 Visual Studio 2017 的 VsDevCmd.bat 会破坏您的 cwd,因此这会变得更加困难。但是,如果你在 worker 上安装以下文件,你可以使用 VS2017 构建:
@ECHO OFF
@REM Calls a single command from the environment set from visual studio vcvars.
@REM Usage:
@REM withvcvars-2017.bat <arch> [command]
@REM
@REM Run VsDevCmd.bat /help to see available arches
@REM See below instantiation for more fine grained option setting.
set ARCH=%1
shift
setlocal enabledelayedexpansion
@rem Replace __ with = in batch files.
@rem This works around idiotic lack of equals signs in args
@rem args contains full args string with substitutions in place
:argloop
if "%~1" NEQ "" (
set str=%~1
set out=!str:__==!
set %~1=!out!
set args=!args!!out!
SHIFT
goto :argloop
)
@rem Aside from batch files being too moronic to allow for equals signs in args,
@rem VsDevCmd.bat idiotically clobbers the current working directory when it's called.
set CWD=%cd%
echo Calling VsDevCmd.bat for arch %ARCH%
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\Tools\VsDevCmd.bat" -arch=%ARCH% -winsdk=8.1 -app_platform=Desktop -no_logo
@rem Who lets these things out the door?
cd %CWD%
@ECHO ON
%args%
完成此操作后,您可以在 bulidbot 主逻辑中创建一个附加此批处理文件的函数:
def _withvcvars(year, arch, cmd):
base_cmd = ["%swithvcvars-%s.bat" % ('\\path\\to\\batchfile\\', year), arch]
return base+cmd
这使您可以运行调用 msbuild.exe 的命令,该命令在其参数中需要等号。只需将它们指定为双下划线:
withvcvars-2017.bat amd64 msbuild.exe your.sln /p:Configuration__Release /p:Platform__x64