Newtonsoft.Json Causes Visual Studio 2015 Code Analysis Failure

The NuGet version of Newtonsoft.Json (version 7.0.1) gives the following error message when starting code analysis.

CA0001 : Could not resolve reference to mscorlib, Version=2.0.5.0, ...

A bug in a portable class library that targets .Net 4.5, Windows 8, and ASP.NET Core 5.0

The error does not occur if the portable class library targets .Net 4.6, Windows Universal 10, and ASP.NET Core 5.0

I took the source code for Newtonsoft.Json and compiled it into a portable class library .Net 4.5, Windows 8, and ASP.NET Core 5.0. Then I referred to the assembly that I compiled instead of the NuGet package. The problem with code analysis does not occur in this case.

Please note that I am using Visual Studio 2105 running on Windows 10. Targeting .Net 4.6 is not an option for me due to other dependencies.

Please let me know if there is a good way to make a NuGet package for the specific purpose of the PCL that I need and code analysis.

+4
source share
2 answers

You can avoid the error by adding CodeAnalysisAdditionalOptions /assemblyCompareMode:Noneto your .csproj file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  ...
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    ....
    <CodeAnalysisAdditionalOptions>/assemblyCompareMode:None</CodeAnalysisAdditionalOptions>
    ....
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    ....
    <CodeAnalysisAdditionalOptions>/assemblyCompareMode:None</CodeAnalysisAdditionalOptions>
    ....
  </PropertyGroup>
  ....
</Project>
0
source

It seems that the bug has been fixed in version 9.0.1 .

0
source

Source: https://habr.com/ru/post/1609200/


All Articles