NuGet(版本7.0.1)中的Newtonsoft.Json版本在运行代码分析时给出以下错误消息.
CA0001 : Could not resolve reference to mscorlib,Version=2.0.5.0,...
该错误发生在以.Net 4.5,Windows 8和Windows为目标的便携式类库中. ASP.NET Core 5.0
如果便携式类库以.Net 4.6,Windows Universal 10和Windows 4为目标,则不会发生错误. ASP.NET Core 5.0
我把Newtonsoft.Json源代码编译成可移植的类库,目标是.Net 4.5,Windows 8& ASP.NET Core 5.0.然后我提到了我编译的程序集而不是NuGet包.在这种情况下,代码分析问题不会发生.
请注意,我使用在Windows 10上运行的Visual Studio 2105.由于其他依赖项,我不能选择.Net 4.6.
解决方法
您可以通过向.csproj文件添加CodeAnalysisAdditionalOptions / assemblyCompareMode:None来避免错误:
<?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>