In a .NET 7 project, I use Serilog (the latest Serilog.Extensions.Logging.File v3.0.0
) and get a bunch of errors NU1605
when trying to compile the project with dotnet publish
:
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)
Upon some digging, I've found that adding the following to my .csproj
file solves the problem:
<PackageReference Include="Microsoft.NETCore.Platforms" Version="7.0.0" />
<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="All" />
However, the Microsoft.NETCore.Targets
package was stopped being updated at v6.0.0-preview.4.21253.7
. Apparently, it has been deprecated, see the "Delete Microsoft.NETCore.Targets package" issue.
To troubleshoot it further, I've enabled "repeatable package restores using a lock file" (the right thing to do for CI builds anyway). Here's what I see in my 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"
}
},
Given that Microsoft.NETCore.Targets
has been deprecated, what is the proper strategy to solve this problem, which I believe can be pretty common these days, now that .NET 3.x LTS is nearing EOL and .NET has been released?
Also, what is the magic behind the current workaround, provided that Microsoft.NETCore.Targets
is basically just an empty package, with a zero-length lib\netstandard1.0\_._
file inside it?