在一个.NET 7项目中,我使用Serilog(最新的Serilog.Extensions.Logging.File v3.0.0
),并在尝试使用dotnet publish
编译项目时得到一系列错误NU1605
:
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
文件中添加以下内容可以解决这个问题:
<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
停止更新。显然,它已经被弃用,请参阅"Delete Microsoft.NETCore.Targets package"问题。
为了进一步排除故障,我启用了"repeatable package restores using a lock file"(无论如何,这是CI构建的正确做法)。
"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.x LTS已接近EOL,而且.NET已发布,解决此问题的策略可能相当普遍。
此外,假设Microsoft.NETCore.Targets
基本上只是一个空包,其中包含一个零长度的lib\netstandard1.0\_._
文件,那么当前的解决方案背后的魔力是什么?
2条答案
按热度按时间dldeef671#
我使用serilog和刚刚更新到.net 7自己。没有任何问题,但我不使用该文件。只有这些:
刚刚注意到Serilog.Extensions.Logging.File使用了不推荐使用的RollingFile接收器。
smdnsysy2#
我至少找到了这部分的答案:
假设
Microsoft.NETCore.Targets
基本上只是一个空包,里面有一个零长度的lib\netstandard1.0\_._
文件,那么当前的解决方案背后有什么魔力呢?这里有一个很好的解释,说明了实际的修复是如何工作的。本质上,
Microsoft.NETCore.Targets
是v3.1.0和更高版本的一个空包,它的唯一目的是覆盖和阻止加载它的任何早期版本,比如来自.NET Core 1.x或2.x的版本:旧版本有一个runtime.json,这会导致包降级