4

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

Pod Mo
  • 262
  • 2
  • 8
KrisT
  • 701
  • 9
  • 22
  • Looks like this project must migrated from vs2010 to vs17 if this has to work. It would be great if someone can confirm this. – KrisT Aug 20 '19 at 15:30
  • 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. – LoLance Aug 20 '19 at 16:26
  • 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. – KrisT Aug 20 '19 at 16:48
  • 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. – LoLance Aug 21 '19 at 02:23
  • But i am using build tools of vs17 from command line. @LanceLi-MSFT – KrisT Aug 21 '19 at 02:32
  • 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. – LoLance Aug 21 '19 at 02:34
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/198210/discussion-between-lance-li-msft-and-krist). – LoLance Aug 21 '19 at 02:37
  • @LanceLi-MSFT okay...give me one hour time. I will go to my workplace and test it out. – KrisT Aug 21 '19 at 02:38
  • 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 :) – LoLance Aug 21 '19 at 02:40

1 Answers1

0

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.

LoLance
  • 18,434
  • 1
  • 12
  • 39
  • Hi @Lance, I want to analyze dotnet project with sonarqube. The problem is sonarscanner is compatible with either msbuild of vs15 or vs17. – KrisT Aug 21 '19 at 06:36
  • @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 Aug 21 '19 at 06:43
  • @KrisT Hi, does the issue persist? – LoLance Aug 21 '19 at 10:12
  • 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? – KrisT Aug 21 '19 at 10:53
  • 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. – LoLance Aug 21 '19 at 11:43