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

1

7

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

Poliomyelitis answered 19/8, 2019 at 13:21 Comment(9)
Looks like this project must migrated from vs2010 to vs17 if this has to work. It would be great if someone can confirm this.Poliomyelitis
As I know, there's several possibilities that can cause this kind of error. But now I can't make sure which situation it belongs to. You can try use older msbuild version at path: C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe or you may check if you install corresponding C# workload when configuring the build tools package.Morrismorrison
Hi @LanceLi-MSFT . As mentioned in the question, msbuild of 3.5 is successfully compiling the code but msbuild of vs17 is failing with the aforementioned error. Note: it is a 3.5 project. Can you tell me which workloads suit this case? I will check if they are present on my system.Poliomyelitis
I haven't had the time to test whether build tools 2017 can build .net 3.5 projects well yesterday, after tests today, I think in normal situations(typical .net console, wpf, web app), there's no need to migrate them. Since you're trying to build them in command-line instead of load them by vs.Morrismorrison
But i am using build tools of vs17 from command line. @LanceLi-MSFTPoliomyelitis
Hi, can you share part of the content of your .csproj file(update it in question)? And please delete the .user file and check if it helps.Morrismorrison
Let us continue this discussion in chat.Morrismorrison
@LanceLi-MSFT okay...give me one hour time. I will go to my workplace and test it out.Poliomyelitis
You can backup the xx.suo in solution folder and the xxx.csproj.user file in project folder in somewhere, and delete the original files to check if this issue is resolved. Since when building a .sln, it exactly is trying to build the projects in that solution. We can chat in the room. Welcome :)Morrismorrison
M
1

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.

Morrismorrison answered 21/8, 2019 at 6:2 Comment(5)
Hi @Lance, I want to analyze dotnet project with sonarqube. The problem is sonarscanner is compatible with either msbuild of vs15 or vs17.Poliomyelitis
@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.Morrismorrison
@KrisT Hi, does the issue persist?Morrismorrison
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?Poliomyelitis
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.Morrismorrison

© 2022 - 2024 — McMap. All rights reserved.