The project file could not be loaded. Root element is missing

12,978

When you use command msbuild xx.sln, you are actually build the projects belonging to the solution.

According to your error message: One of the project's project file (xx.csproj) is not loaded cause the msbuild can't read the xml content well. You can try:

1.Open the xx.csproj file and make sure its format is:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
</Project>

2.Save it with UTF-8 encoding to avoid BOM be messed up

3.Backup and then delete the .suo and .csproj.user files

4.Otherwise, since it's a asp.net mvc project, you can create a same-name asp.net mvc project by vs2017, copy all the source files to the new project to migrate the project to VS2017

5.Make sure your build tools package install the web development workload:

enter image description here

6.Since it works well when using msbuild from .net3.5, you can install the .net framework 3.5 in your server and try calling the msbuild from C:\Windows\Microsoft.NET\Framework64\v3.5 instead of C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin when building .net 3.5 projects from vs2010.

Share:
12,978
CK5
Author by

CK5

I'm passionate about setting up strong &amp; self-healing CICD pipeline. And, I ask lot of questions :)

Updated on December 13, 2022

Comments

  • CK5
    CK5 11 months

    I am trying to build a dotnet 3.5 project solution file with VS Build tools 2017 in Jenkins. The project is compiling well with DotNet 3.5's MSBuild, but when I try the same activity with MSBuild Engine Version 15.9.21+g9802d43bc3, it is throwing MSBUILD : error MSB4025: The project file could not be loaded. Root element is missing.

    This is the command which I have used to compile dotnet 3.5 project.

    cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
    MSBuild.exe "%WORKSPACE%\WBR.sln" /p:Configuration=Debug /p:DeployOnBuild=True /p:AllowUntrustedCertificate=True /p:CreatePackageOnPublish=True
    

    Please find below Jenkins execution logs

    C:\Users\Netadmin\.jenkins\jobs\FCRS\jobs\FCRS_VS\workspace>cd "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin" 
    
    C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin>MSBuild.exe "C:\Users\Netadmin\.jenkins\jobs\FCRS\jobs\FCRS_VS\workspace\WBR.sln" /p:Configuration=Debug /p:DeployOnBuild=True /p:AllowUntrustedCertificate=True /p:CreatePackageOnPublish=True 
    Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
    Copyright (C) Microsoft Corporation. All rights reserved.
    
    Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
    Build started 8/19/2019 6:38:12 PM.
    MSBUILD : error MSB4025: The project file could not be loaded. Root element is missing.
    
    Build FAILED.
    
      MSBUILD : error MSB4025: The project file could not be loaded. Root element is missing.
    
        0 Warning(s)
        1 Error(s)
    

    The below pic is my jenkins workspace directory.

    Any help would be great.

    enter image description here

  • CK5
    CK5 about 4 years
    Hi @Lance, I want to analyze dotnet project with sonarqube. The problem is sonarscanner is compatible with either msbuild of vs15 or vs17.
  • LoLance
    LoLance about 4 years
    @KrisT Have you tried 1.2.3? If it not works, you can create a new vs2017 empty project to migrate the vs2010 project to vs2017(This way always work). Or you may need to share the content of xx.csproj so we can look deeper to check where the cause of the issue is.
  • LoLance
    LoLance about 4 years
    @KrisT Hi, does the issue persist?
  • CK5
    CK5 about 4 years
    I have asked the developer to share the project file. But I have a query. As you saw in the pic, there are 5-6 modules within this solution file. Should I work and show all project files?
  • LoLance
    LoLance about 4 years
    That's peoject file,not solution file in the script above. I just want to check the format, so the details in propertygroup and itemgroup can be ignored.