]> TFS Error CS1679: Invalid extern alias for '/reference' 🌐:aligrant.com

TFS Error CS1679: Invalid extern alias for '/reference'

Alastair Grant | Monday 5 November 2018

As you can probably see by my recent posts, I've been ankle deep in TFS build agents recently.  My latest head scratching moment was configuring automated builds for a sprawl of code.  I was hoping that this project would be in a buildable state when I looked at it, and was disheartened to find this error spewed everywhere:

CSC : error CS1679: Invalid extern alias for '/reference'; 'C:\vstsagent\A2\' is not a valid identifier [C:\vstsagent\A2\=_work\1\s\blah\blah.csproj]

extern alias is used to reference two different versions of the same assembly in a project.  This raised my eyebrows as I couldn't imagine this project needing anything so complex.  Rummaging through the code I couldn't find any uses of the extern alias keywords.  Which left me puzzled and resorting to searching the net for clues.

Not a lot came up, certainly nothing recent - which meant I'm on my own.  The project built fine locally (well, it did with some fixing), but the error persisted through msbuild on TFS.  Narrowing down my searches, one loan result jumped out at me for some reason: Equals signs in solution path causes CS1679.  Who in their right mind would put an equals sign in a file path?

The answer was staring me in the face and the answer to the question is me, I'm the person who put an equals sign in a file path: but not in the project, in the build agent.

it looks like when I configured the build agent (tinkering by hand with the command line arguments), it appears I had somehow entered in --work=_work instead of --work '_work' (guess somebody is used to *nix where convention says -- has an equals between the argument and its value, and a single - uses an abbreviated argument name and a space separator for the value).

The fix is straight forward.  You don't have to reconfigure your agent from scratch, you can stop the process and edit the .agent JSON file in the agent's root directory (might be hidden), and alter the "workFolder" value to be the correct one.  Start up the agent again and life is back to normal.

Breaking from the voyeuristic norms of the Internet, any comments can be made in private by contacting me.