Tuesday, May 23, 2017

TFS Build Error - works in Command Prompt, doesn't work in TFS Build Definition

I've been getting into TFS Builds lately (using VNext, Wix, etc - not XAML).  In particular, I'm using TFS 2015, which I installed to a local VM.

I was able to successfully build a project off a DOS prompt (it's now called the "Developer Command Prompt" in more modern Windows Servers... ☺) using the MSBuild.exe command.  However I was not able to get a successful build when using the MSBuild step.  I even went a little further and decided to use the Command Line step in the definition and typed in the exact same command line that I used off the dos prompt above.  Even that didn't work.

The errors I kept on seeing in the log files were ambiguous to me - a whole bunch of ICE and LGHT errors.  Almost all of them referred to an "incorrectly registered scripting engine":


The errors didn't make much sense to me.  So instead of getting too focused on the error messages, I took a step back and reviewed what is going on: I was using the same exact command line - one using via the local server Command Prompt (success), and the other being called within TFS Build Command Line step (fail).


Conclusion:  permissions


I talked with a co-worker about this (he is a bit more seasoned with TFS Builds) and one of the first question he asked was: "How is your Agent set up?"

Looking at a few things we (he) figured it out.  My settings.json file in the appropriate agent folder was not properly set up.  In particular, the "WindowsServiceName" setting was blank.  I *think* that if it's blank, it uses 'Local Service' or something like that.  Either way, it's not a best practice.

I reconfigured the agent to use the appropriate service.  I reviewed the updated configuration to make sure that the setting was now populated.  After that my MSBuild step was running without a hitch.