Sitecore, XM Cloud, XM Cloud Deploy

How to fix XM Cloud deployment failing to build

In this article we will look into how to fix the XM Cloud deployment build step failure issue.

Problem

Let’s have some background first! I’m working on the XM Cloud project for which we have 4 different environments created in XM Cloud environment. Till date 11 June 2024, everything was working fine with existing projects being used in the deployment to the XM Cloud environment. On next day all of a sudden, we started to see the build failure for one of the projects for which the msbuild was not able to find the referenced NuGet packages.

Resolution

As we observed that XM Cloud deployments are failing, we started looking into the logs. As stated in the problem description, we found following type of error(s) in the XM Cloud deployment logs.

06/13/2024 05:29:31 +00:00|INFO|_CleanRecordFileWrites:
06/13/2024 05:29:31 +00:00|INFO|Creating directory "obj\Release\".
06/13/2024 05:29:31 +00:00|INFO|Done Building Project "C:\b\18279613\src\Feature\SEO\code\xxx.Feature.SEO.csproj" (default targets) -- FAILED.
06/13/2024 05:29:31 +00:00|INFO|Done Building Project "C:\b\18279613\src\Project\xxx\xxx.csproj" (default targets) -- FAILED.
06/13/2024 05:29:31 +00:00|INFO|Done Building Project "C:\b\18279613\xxx.sln" (default targets) -- FAILED.
06/13/2024 05:29:31 +00:00|INFO|Build FAILED.
06/13/2024 05:29:31 +00:00|INFO|"C:\b\18279613\xxx.sln" (default target) (1) ->
06/13/2024 05:29:31 +00:00|INFO|"C:\b\18279613\src\Project\PSP\xxx.csproj" (default target) (2) ->
06/13/2024 05:29:31 +00:00|INFO|"C:\b\18279613\src\Feature\SEO\code\xxx.Feature.SEO.csproj" (default target) (3:2) ->
06/13/2024 05:29:31 +00:00|INFO|(EnsureNuGetPackageBuildImports target) ->
06/13/2024 05:29:31 +00:00|INFO|C:\b\18279613\src\Feature\SEO\code\xxx.Feature.SEO.csproj(141,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\..\..\..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1\build\net46\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props.
06/13/2024 05:29:31 +00:00|INFO|0 Warning(s)
06/13/2024 05:29:31 +00:00|INFO|1 Error(s)
06/13/2024 05:29:31 +00:00|INFO|Time Elapsed 00:00:01.44
06/13/2024 05:29:31 +00:00|ERROR|Build terminated due to failure
06/13/2024 05:29:31 +00:00|ERROR|Build terminated due to failure
06/13/2024 05:29:31 +00:00|ERROR|Build has failed.

As the log lines show, the NuGet package not found, we investigated in the code solution to see if there is any change for reference or not.

We went through the Git history, but found nothing suspicious.

As we faced the issue on the QA environment, we tried to reproduce the issue on DEV by deploying the code and found the same issue. To be double sure, we triggered UAT deployment and that also failed at the build stage.

Before we move our investigation, it was advisable that we raise the Sitecore support ticket so that we should get some quick fix if they have observed such issue.

We started a fresh investigation by comparing the failed deployment logs against the successful deployment logs.

During the comparison, we found something interesting. For the failed deployment, in the log file we found the following entry for the MSBuild version

06/13/2024 05:29:08 +00:00|INFO|Created resource package items.master.xmcloudjss.dat of MASTER database in C:\artifacts\items\xmcloud directory
06/13/2024 05:29:09 +00:00|INFO|Restoring packages for solution ./PetSuppliesPlus.sln
06/13/2024 05:29:10 +00:00|INFO|MSBuild version 17.10.4+10fbfbf2e for .NET Framework
06/13/2024 05:29:10 +00:00|INFO|Build started 6/13/2024 5:29:10 AM.
06/13/2024 05:29:11 +00:00|INFO|1>Project "C:\b\18279613\xxx.sln" on node 1 (Restore target(s)).
06/13/2024 05:29:11 +00:00|INFO|1>ValidateSolutionConfiguration:
06/13/2024 05:29:11 +00:00|INFO|Building solution configuration "Debug|Any CPU".

While in the log file for the successful deployment we found the following entry for the MSBuild version.

06/11/2024 10:06:42 +00:00|INFO|Created resource package items.master.xmcloudjss.dat of MASTER database in C:\artifacts\items\xmcloud directory
06/11/2024 10:06:42 +00:00|INFO|Restoring packages for solution ./xxx.sln
06/11/2024 10:06:43 +00:00|INFO|MSBuild auto-detection: using msbuild version '17.10.4.21802' from 'C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin'.
06/11/2024 10:06:48 +00:00|INFO|Restoring NuGet package Sitecore.XmCloud.Kernel.1.5.50.
06/11/2024 10:06:48 +00:00|INFO|Restoring NuGet package Sitecore.XMCloud.Assemblies.1.5.50.
06/11/2024 10:06:48 +00:00|INFO|Restoring NuGet package Microsoft.CodeDom.Providers.DotNetCompilerPlatform.2.0.1.
06/11/2024 10:06:48 +00:00|INFO|Restoring NuGet package Sitecore.XmCloud.LayoutService.1.5.50.

And as seen in the above snippet, we can see that right after detecting the MSBuild, the NuGet package restoration happened for the successful deployment, while the same entries are missing for the failed deployment.

Now, it has been clear that there is something related to MSBuild caused the sudden failed deployment.

We don’t know whether Sitecore has changed or not the VS version on their end for XM Cloud Deploy pipelines which caused the deployment failure as we have enquired with other XM Cloud project team members and found that they are not facing such issues. But I had the strong filling that there must be something from Sitecore which caused this issue.

Now our first action was to remove that faulty .csproj and try the deployment. We found that deployment went successful. It means, we have something which is causing the issue.

After investigating sometime, we found the different in the NuGet package reference approach between the Sitecore provided .csproj and our created project.

The difference was, Sitecore provided project was using the Central Package Referencing while our project was using the project specific NuGet package referencing from Packages.config file which is residing in the project directory.

As a next action, we cleared all the NuGet package references by modifying the .csproj file to make sure no previous references are entertained.

After that, by referring the Sitecore provided .csproj file, we took the package references into our project .csproj file.

Also to be sure on the Visual Studio side, we did make sure that the Visual Studio is set to use the PackageReference instead of the Packages.config file. You can change the setting from the Tools > Options… > NuGet Package Manager > General section.

After changing the project reference to use the central package manager, and adding that project back to the solution, we tested the changes on the local system and then we tried deploying it on the XM Cloud environment.

The deployment went successful and we were too much delighted that we were able to fix the issue.

Later, on 13th June 2024, we updated out Sitecore support ticket to let Sitecore know that we were able to fix our issue by explaining out steps taken. Sitecore has responded with the following updates which proved our assumption that it must some side effect of the Sitecore issue fix. Click here to know more about the issue.

I thought to share the solution we applied to make sure I should save time for the developers like me who are using XM Cloud.

Thanks and happy fixing!!!