.net core build error when building docker image missing Newtonsoft.Json

In my case, When used JsonProperty in a class,

Visual Studio intellicode auto-filled,

using Newtonsoft.Json;

Then during docker build,

warning MSB3245: Could not resolve this reference. Could not locate the assembly "Newtonsoft.Json". Check to make sure the assembly exists on disk.

When I checked, found out that the Visual Studio added an Assembly Reference to Newtonsoft.Json (you can find this by expanding Dependencies node in the solution explorer in Visual Studio). And I was using Linux images.

So in order to solve this, I removed the Assembly Reference, and added nuget package Newtonsoft.Json, then the docker build was successful.


Found the issue. Update NuGet package Microsoft.VisualStudio.Azure.Containers.Tools.Targets to latest version and the problem goes away.