简体   繁体   中英

MSBuild errors out on build server but not on dev-machines

"someSolutionFile.sln: error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 2, position 1"

The MSBuild invocation which errors out is really simple:

<MSBuild
  Projects="someSolutionFile.sln"
  Targets="someProject.csproj"
  Properties="..."
  BuildInParallel="false"
/>

Both dev-machines and the build server use the exactly same msbuild version:

Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Framework

Why could it be that only the build server errors out but not the dev-machines?

Turns out that one of the merges on the .sln accidentally removed an [endproject] section. The error message was really misleading as to what was amiss:

 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8DCAA708-E9BE-4C30-B267-F60B2F36C031}"
    ProjectSection(SolutionItems) = preProject
        Performance1.psess = Performance1.psess
    EndProjectSection
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "[some project 1]", "[some project 1].csproj", "{2CD27468-B1D4-4380-BF06-78CCDDCE53C2}"
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "[some project 2]", "[some project 2].csproj", "{0DB85F19-4E9E-417D-828D-D44566554B5F}"
 EndProject  <--- this was missing

If you have such problems Visual Studio somehow won't complain. To re-normalize the .sln file simply:

  1. Add a dummy new project to the solution and save the solution as a whole
  2. Delete the dummy project you just added and re-save the solution

The .sln file should be sane now. You may commit it to your branches.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM