Different Newtonsoft.Json.dll dotnet publish vs publish with Visual Studio

629 Views Asked by At

I have a .NET Core Web Application with target framework .netcoreapp2.0.

If i publish my application via Visual Studio (folder profile) I get a different Newtonsoft.Json.dll then with the command dotnet publish --configuration Release --output D:/publish/Frontend /property:PublishWithAspNetCoreTargetManifest=false

VS publish version:

VS publish version

dotnet publish version:

enter image description here

The created file AutomaticConfirmationWebfrontend.deps.json has always this dependency:

"runtime": {
          "lib/netstandard1.3/Newtonsoft.Json.dll": {
            "assemblyVersion": "10.0.0.0",
            "fileVersion": "10.0.1.20720"
          }
        }

This results in a problem for my CI/CD process where I publish my app with the command dotnet publish. If I open the website I get an error message that the assembly Newtonsoft.JSON 10.0.0.0 could not be found. If i copy manually the DLL with version 10.0.0.0 to the application folder it works! Debugging my application locally works also fine!

I have no Newtonsoft NuGet package installed. I think I am using the built in package from .NET Core.

In my Startup.cs I have the following line of code:

services.AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());

I need this for lowercase JSON objects. I have imported this namespace:

using Newtonsoft.Json.Serialization

Anybody an idea what I'm doing wrong or how to fix this?

2

There are 2 best solutions below

0
On

Late answer but it may help someone in future. Within the solution some other (other project) NuGet package also depending Newtonsoft.Json.dll. Check all your NuGet package dependencies especially Testing projects which may be mapped with low version Newtonsoft.Json.dll. (Refer below pic).

enter image description here

If that is the problem, then you can map .csproj file in your publish command like below,

dotnet publish src/myproject.csproj --configuration Release --output D:/publish/Frontend /property:PublishWithAspNetCoreTargetManifest=false
0
On

I did 3 steps:

  1. Upgraded to netcoreapp3.1
  2. Removed all nuget packages from C:\Users\******\.nuget\packages
  3. Installed the latest MSBuild installer