Execute file with variable path in PowerShell CI Runner

I’m trying to execute msbuild.exe without cd’ing to the path it resides in first.
Since the path to msbuild.exe is rather long and i’d like to be able to change it, I defined it as a variable “MSBUILD”.

But I can’t get the Runner to properly execute it. Either There are errors about missing values for “/” parameters:

  • $MSBUILD /consoleloggerparameters:ErrorsOnly

I also tried defining the Path as a variable and appending the static “MSBuild.exe”:

  • $MSBUILDDIR\MSBuild.exe […]

Which fails with “unexpected token: \MSBuild.exe”

I’ve tried all combinations of Quoting around Variables and Parameters of MSBuild. Either the path to MSBuild isn’t interpreted correctly, or the command parameters aren’t recognized…

What am I doing wrong here? Can somebody supply an example on how to call an executable with parameters in GitLab CI with PowerShell Executor?

Edit: The only thing that works is

  • cd $MSBUILDDIR
  • .\MSBuild.exe

Which I’d like to avoid as it would require even more CMDs to cd back to the original directory, cluttering up CI files. I’m sure there is a way to call an executable w/ variable path and params in one line for PS.