首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Serilog,.NET 7,错误NU1605 (“检测到的包降级”)和Microsoft.NETCore.Targets

Serilog,.NET 7,错误NU1605 (“检测到的包降级”)和Microsoft.NETCore.Targets
EN

Stack Overflow用户
提问于 2022-11-15 23:28:55
回答 2查看 92关注 0票数 1

在.NET 7项目中,我使用了Serilog (最新的Serilog.Extensions.Logging.File v3.0.0),并在尝试用dotnet publish编译项目时获得了大量错误( NU1605 )。

代码语言:javascript
运行
复制
Agent.csproj : error NU1605: Detected package downgrade: System.IO from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. 
Agent.csproj : error NU1605:  Agent -> Serilog.Extensions.Logging.File 3.0.0 -> Serilog.Sinks.RollingFile 3.3.0 -> Serilog.Sinks.File 3.2.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.IO (>= 4.3.0) 
Agent.csproj : error NU1605:  Agent -> Serilog.Extensions.Logging.File 3.0.0 -> Serilog.Sinks.RollingFile 3.3.0 -> System.IO (>= 4.1.0)
Agent.csproj : error NU1605: Detected package downgrade: System.IO.FileSystem.Primitives from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. 
Agent.csproj : error NU1605:  Agent -> Serilog.Extensions.Logging.File 3.0.0 -> Serilog.Sinks.RollingFile 3.3.0 -> Serilog.Sinks.File 3.2.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.IO.FileSystem.Primitives (>= 4.3.0) 
Agent.csproj : error NU1605:  Agent -> Serilog.Extensions.Logging.File 3.0.0 -> Serilog.Sinks.RollingFile 3.3.0 -> System.IO.FileSystem.Primitives (>= 4.0.1)
Agent.csproj : error NU1605: Detected package downgrade: System.Runtime.Handles from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. 
Agent.csproj : error NU1605:  Agent -> Serilog.Extensions.Logging.File 3.0.0 -> Serilog.Sinks.RollingFile 3.3.0 -> Serilog.Sinks.File 3.2.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Handles (>= 4.3.0) 
Agent.csproj : error NU1605:  Agent -> Serilog.Extensions.Logging.File 3.0.0 -> Serilog.Sinks.RollingFile 3.3.0 -> Serilog.Sinks.File 3.2.0 -> System.IO.FileSystem 4.0.1 -> System.Runtime.Handles (>= 4.0.1)

经过深入研究,我发现将以下内容添加到我的.csproj文件中可以解决这个问题:

代码语言:javascript
运行
复制
    <PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.0" />
    <PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="All" />

但是,Microsoft.NETCore.Targets包在v6.0.0-preview.4.21253.7上停止更新。显然,它已经被否决了,参见“删除Microsoft.NETCore.Targets包”问题。

为了进一步排除故障,我启用了“使用锁文件进行可重复的包还原” (不管怎么说,对于CI构建来说都是正确的)。这是我在我的packages.lock.json中看到的

代码语言:javascript
运行
复制
      "Serilog.Sinks.RollingFile": {
        "type": "Transitive",
        "resolved": "3.3.0",
        "contentHash": "2lT5X1r3GH4P0bRWJfhA7etGl8Q2Ipw9AACvtAHWRUSpYZ42NGVyHoVs2ALBZ/cAkkS+tA4jl80Zie144eLQPg==",
        "dependencies": {
          "Serilog.Sinks.File": "3.2.0",
          "System.IO": "4.1.0",
          "System.IO.FileSystem.Primitives": "4.0.1",
          "System.Runtime.InteropServices": "4.1.0",
          "System.Text.Encoding.Extensions": "4.0.11"
        }
      },

// ...

      "System.IO": {
        "type": "Transitive",
        "resolved": "4.1.0",
        "contentHash": "3KlTJceQc3gnGIaHZ7UBZO26SHL1SHE4ddrmiwumFnId+CEHP+O8r386tZKaE6zlk5/mF8vifMBzHj9SaXN+mQ==",
        "dependencies": {
          "Microsoft.NETCore.Platforms": "1.0.1",
          "Microsoft.NETCore.Targets": "1.0.1",
          "System.Runtime": "4.1.0",
          "System.Text.Encoding": "4.0.11",
          "System.Threading.Tasks": "4.0.11"
        }
      },
      "System.IO.FileSystem": {
        "type": "Transitive",
        "resolved": "4.0.1",
        "contentHash": "IBErlVq5jOggAD69bg1t0pJcHaDbJbWNUZTPI96fkYWzwYbN6D9wRHMULLDd9dHsl7C2YsxXL31LMfPI1SWt8w==",
        "dependencies": {
          "Microsoft.NETCore.Platforms": "1.0.1",
          "Microsoft.NETCore.Targets": "1.0.1",
          "System.IO": "4.1.0",
          "System.IO.FileSystem.Primitives": "4.0.1",
          "System.Runtime": "4.1.0",
          "System.Runtime.Handles": "4.0.1",
          "System.Text.Encoding": "4.0.11",
          "System.Threading.Tasks": "4.0.11"
        }
      },

考虑到Microsoft.NETCore.Targets已经被废弃,有什么合适的策略来解决这个问题-,我认为这个问题现在很常见,现在.NET 3.xLTS已经接近了EOL,.NET已经发布了?

此外,如果Microsoft.NETCore.Targets基本上只是一个空包,其中包含一个零长度的lib\netstandard1.0\_._文件,那么当前解决方案背后的神奇之处是什么?

EN

回答 2

Stack Overflow用户

发布于 2022-11-16 00:56:38

我使用serilog并自己更新到.net 7。没有任何问题,但我不使用那个文件。只有这些:

代码语言:javascript
运行
复制
  <PackageReference Include="Serilog.AspNetCore" Version="6.0.1" />
  <PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
  <PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />

刚刚注意到Serilog.Extensions.Logging.File使用了不推荐的RollingFile接收器。

票数 1
EN

Stack Overflow用户

发布于 2022-11-16 06:19:18

我找到了至少这部分的答案:

如果Microsoft.NETCore.Targets基本上只是一个空包,其中包含一个零长度的lib\netstandard1.0\_._文件,那么当前解决方案背后的神奇之处是什么?

下面是实际修复如何工作的很好的解释。从本质上说,Microsoft.NETCore.Targets是v3.1.0和on中的一个空包,它的唯一目的是覆盖和防止加载任何早期版本,比如.NET Core1.x或2.x中的版本:

旧版本有一个runtime.json,它导致软件包降级。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74453395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档