【问题标题】:Fixing C# dotnetcore3.1 log4net 2.0.8: Detected package downgrade error修复 C# dotnetcore3.1 log4net 2.0.8:检测到包降级错误
【发布时间】:2020-04-17 17:30:25
【问题描述】:

我正在尝试让 log4net 在 dotnetcore3.1 项目下工作。我不断收到这样的错误信息:

error NU1605: Detected package downgrade: System.Diagnostics.Debug from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version.  [/app/MyProject.csproj]

csproj 归结为:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <OutputType>exe</OutputType>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="log4net" Version="2.0.8" />
  </ItemGroup>
</Project>

环境:

  • dotnetcore3.1
  • docker 构建镜像:mcr.microsoft.com/dotnet/core/sdk:3.1
  • docker 运行时映像:mcr.microsoft.com/dotnet/core/runtime:3.1-bionic

不可接受的“修复”:

  • “只需添加&lt;WarningsAsErrors&gt;&lt;/WarningsAsErrors&gt;
  • 任何涉及打开 Visual Studio 的事情

这个问题有几个帖子,但他们似乎要么压制错误并继续前进,要么他们使用 Visual Studio“魔法”来解决它。

根据这条消息 Reference the package directly from the project to select a different version.,我尝试将包引用添加到我的 csproj,但“System”、“System.Diagnostics”或“System.Diagnostics.Debug”都不起作用。

你是如何真正解决这个问题的?

请具体说明。我还是 C# 的新手,我发现的许多解决方案可能都不起作用,因为他们只是说添加 &lt;SomeXmlTag /&gt; 而我不知道将它放在哪里或放在哪个父级下删除标签。


每只灰猫,我都试过了:Adding a bindingRedirect to a .Net Standard library

最初它似乎根本没有改变输出。在玩了冗长之后,我发现了这个:

   "/app/MyProject.csproj" (Publish target) (1) ->
   (ResolveAssemblyReferences target) -> 
/usr/share/dotnet/sdk/3.1.100/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Configuration.ConfigurationManager" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/app/MyProject.csproj]
     /usr/share/dotnet/sdk/3.1.100/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.AccessControl" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/app/MyProject.csproj]
     /usr/share/dotnet/sdk/3.1.100/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Permissions" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/app/MyProject.csproj]
     /usr/share/dotnet/sdk/3.1.100/Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "System.Security.Principal.Windows" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [/app/MyProject.csproj]

太好了,它应该包含详细信息,但我在我正在查看的输出页面中找不到它们。

【问题讨论】:

  • 这有帮助吗:stackoverflow.com/questions/46111749/…?我认为直接添加依赖项没有帮助这很奇怪,但绑定重定向应该。只是祈祷有问题的库是向后兼容的。
  • 我刚试过。除非我错过了什么,否则输出没有变化。
  • 那么也许你应该看看 .NET Core 3.1 中的新型引用 - FrameworkReference。你可以在这里阅读更多相关信息:andrewlock.net/… 也许这会帮助你把好的包裹放进去。
  • 是的,log4net 仅支持在 NuGet 中检查的 .NET Standard 1.3。您可以做的最好的事情就是使用另一个记录器。版本之间的差距越大,问题就越模糊。
  • “写了我自己的记录器”请不要。按照@GrayCat 的建议,使用 .NET Core 的内置日志记录功能或支持 Core 3.1 的日志记录框架。日志记录是一个已经解决了很多次的问题,不要重新发明这个轮子。

标签: c# linux .net-core nuget log4net


【解决方案1】:

在尝试构建我们的一些 .NET Core 3.1 服务时,我们遇到了类似的问题。 降级消息是相同的,尽管对于不同的库(尽管它们都来自 System.* 命名空间)

我设法通过在 .csproj 文件中添加以下行来解决问题

<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" PrivateAssets="all" />

该解决方案由 Microsoft 提出并记录在此: https://docs.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1605(示例2)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-21
    • 2021-03-18
    • 2021-08-22
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多