I solved this problem a little differently. I install a batch file on the Windows worker which, upon launching, calls the environment setting batch file, then executes the intended command. This is, of course, made harder by the fact that batch files are horrible at forwarding arguments, and by the fact that Visual Studio 2017's VsDevCmd.bat clobbers your cwd. However, if you install the following file on the worker, you can build with 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%
Once this is done, you can create a function in your bulidbot master logic which appends this batch file:
def _withvcvars(year, arch, cmd):
base_cmd = ["%swithvcvars-%s.bat" % ('\\path\\to\\batchfile\\', year), arch]
return base+cmd
This lets you runs commands wherein you call msbuild.exe which expects equals signs in its arguments. Just specify them as double underscores:
withvcvars-2017.bat amd64 msbuild.exe your.sln /p:Configuration__Release /p:Platform__x64