The project file could not be loaded. Data at the root level is invalid. Line 2, position 1 error in TeamCity

Whilst compiling a project locally on my development box (using Visual Studio 2015) everything was fine. However, as soon as I pushed my build up and TeamCity picked it up, TeamCity failed the build almost immediately. The error message wasn’t particuarly helpful.

The project file could not be loaded. Data at the root level is invalid. Line 2, position 1.

If you google the error you will see lots of people providing lots of different solutions. To cut to the chase, running MSBuild at the command prompt on your development box will give you more information.

msbuild.exe "myproject.sln" /t:build

The problem I had was some projects had been removed from the solution but their GUIDs were still being referenced. Removing them from the solution file and recompiling solved the issue.