devops pipeline publishing wrong assembly version (of newtonsoft.json)

Viewed 274

I have a Blazor webassembly solution (hosted by aspnet.core webapi) which builds and runs fine locally. Server and Client reference directly newtonsoft.json.dll version 13.0.1. The server also has a reference to Microsoft.AspNetCore.Mvc.NewtonsoftJson which shows a dependency to newtonsoft.json of >=12.0.

If after compiling I search locally in the bin folders, ALL projects have version 13.0.1 but one 12.0.3 in the BlazorDebugProxy folder.

Now building,publishing and running the app via azure results in error:

Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. The system cannot find the file specified. File name: 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' at Microsoft.AspNetCore.Mvc.MvcNewtonsoftJsonOptions..ctor()

Looking at the files in the artifacts which the build created, it is version 9.0.1 ! The only hint why this file might be the wrong version is that this is the Net Standard 1 version. However the projects all have version 5 in their csproj files, so it should not pull any framework 1 stuff and it does not locally.

I added a step to install Net 5 SDK and when starting the restore process it correctly reports that SDK version 5.0.402 is used.

In the pre Net Core world such issues where easily resolved with an assembly rebind, what do I do now ?

1 Answers

I finally figured it out and it's a bad behavior of the devops pipelines. The issue is that publish will internally do a build and if that is set to the whole solution, it just copies all dll's to the publish folder.

I had the build task set to just build my web project, but forgot to do the same for the publish.

Once I did set this, the correct dll was copied (what is references in the csproj file takes precedence to any other versions).

The ONLY reason one needs a separate build task is if there are other projects to build beside the one to publish, in most cases (mine) test projects.

Related