Newtonsoft Version conflicts with Azure Function & PnP-Sites-Core

Compilation Warnings

Warning NU1608 Detected package version outside of dependency constraint: Microsoft.NET.Sdk.Functions 1.0.24 requires Newtonsoft.Json (= 9.0.1) but version Newtonsoft.Json 10.0.3 was resolved.

The Cause:

The Function App references a Business Layer project, which references the OfficePnP.Core NuGet package, which Newtonesoft.Json version 10.0.3

The Function App reference the Microsoft.NET.Sdk.Functions (version 10.0.24), which unfortunately references the Newtonesoft.Json version 9.0.1

The project builds with the NU1608 Warning, and causes the following code to throw an error:

XMLTemplateProvider provider = new XMLFileSystemTemplateProvider(templateFilePath, string.Empty);
ProvisioningTemplate template = provider.GetTemplate(templateFileName);

The “Fix”:

I have manually updated the Function Apps .CSProj file to include the following reference:

<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />

This causes the Dependency and NuGet folders to show a warning triangle, however the project builds and the PnP ProvisioningTemplate loads OK.

More Information:

I also attempted a downgrade of the Business Layer project SharePointPnPCoreOnline NuGet reference to version: 2.24.1803 (this references Newtonesoft.Json version 9.0.1), however the following code failed to work:

ProvisioningTemplate template = provider.GetTemplate(templateFileName);

MSBuild task for Azure Functions
https://github.com/Azure/azure-functions-vs-build-sdk
Newtonsoft.Json
https://www.nuget.org/packages/Newtonsoft.Json