[英]NU1605 Detected package downgrade error when try the Publish project
[英]Serilog, .NET 7, error NU1605 ("detected package downgrade") and Microsoft.NETCore.Targets
在 .NET 7 項目中,我使用 Serilog(最新的Serilog.Extensions.Logging.File v3.0.0
)並在嘗試使用do.net 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
package 在v6.0.0-preview.4.21253.7
停止更新。 顯然,它已被棄用,請參閱“刪除 Microsoft.NETCore.Targets 包”問題。
為了進一步排除故障,我啟用了“使用鎖定文件進行可重復的 package 恢復” (無論如何對 CI 構建來說都是正確的做法)。 這是我在packages.lock.json
中看到的內容:
"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
基本上只是一個空的 package,其中包含一個零長度的lib.netstandard1.0\_._
文件,那么當前解決方法背后的魔力是什么?
我使用 serilog 並自己更新到 .net 7。 沒有任何問題,但我沒有使用該文件。 只有這些:
<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 接收器。
我至少找到了這部分的答案:
如果
Microsoft.NETCore.Targets
基本上只是一個空的 package,其中包含一個零長度的lib.netstandard1.0\_._
文件,那么當前解決方法背后的魔力是什么?
這是對實際修復工作原理的很好解釋。 從本質上講, Microsoft.NETCore.Targets
是 v3.1.0 及更高版本的空 package,它的唯一目的是覆蓋和防止加載其任何早期版本,例如 .NET Core 1.x 或 2.x 中的版本:
舊版本有一個 runtime.json 導致 package 降級
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.