serilog-sinks-file
serilog-sinks-file copied to clipboard
serilog-sinks-file 5.0.0 gives error while publishing self-contained
I have updated the version of the package from 4.1.0 to 5.0.0
After the update the project build but if I try to publish the solution with the self-contained switch if fails. My project is in NET 5.
Here is the build error log:
error NU1605: Detected package downgrade: System.Collections from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. error NU1605: MyProject -> Serilog.AspNetCore 4.1.0 -> Serilog.Settings.Configuration 3.1.0 -> Microsoft.Extensions.DependencyModel 2.0.4 -> Microsoft.DotNet.PlatformAbstractions 2.0.4 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Collections (>= 4.3.0) error NU1605: MyProject -> Serilog.AspNetCore 4.1.0 -> Serilog.Settings.Configuration 3.1.0 -> Microsoft.Extensions.DependencyModel 2.0.4 -> Microsoft.DotNet.PlatformAbstractions 2.0.4 -> System.Collections (>= 4.0.11) 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. error NU1605: MyProject -> Serilog.AspNetCore 4.1.0 -> Serilog.Settings.Configuration 3.1.0 -> Microsoft.Extensions.DependencyModel 2.0.4 -> Microsoft.DotNet.PlatformAbstractions 2.0.4 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Diagnostics.Debug (>= 4.3.0) error NU1605: MyProject -> Serilog.AspNetCore 4.1.0 -> Serilog.Settings.Configuration 3.1.0 -> Microsoft.Extensions.DependencyModel 2.0.4 -> System.Diagnostics.Debug (>= 4.0.11) error NU1605: Detected package downgrade: System.Runtime.Extensions from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. error NU1605: MyProject -> Serilog.AspNetCore 4.1.0 -> Serilog.Settings.Configuration 3.1.0 -> Microsoft.Extensions.DependencyModel 2.0.4 -> Microsoft.DotNet.PlatformAbstractions 2.0.4 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Extensions (>= 4.3.0) error NU1605: MyProject -> Serilog.AspNetCore 4.1.0 -> Serilog.Settings.Configuration 3.1.0 -> Microsoft.Extensions.DependencyModel 2.0.4 -> Microsoft.DotNet.PlatformAbstractions 2.0.4 -> System.Runtime.Extensions (>= 4.1.0)
I have checked the commit history and the only change was in serilog-sinks-file, so I try to rollback and everything works.
Here is my the part of my release script that gives error:
dotnet publish .\MyProject.csproj --self-contained true --runtime win-x64
Thanks for the heads-up!
Serilog.Sinks.File 5.0 now has a net5.0
target, which I'd hoped would skirt around this issue for that platform, but looks like that might have been unsuccessful :-(. The package previously explicitly referenced the 4.3.x versions of several assemblies to attempt this, but that was in itself problematic and not a long-term fix.
The root cause appears to be that at build time, the dependency resolution algorithm (incorrectly?) treats assemblies .NET (Core) framework packages as though they're going to be bundled with the app, and resolves them to a specific version via whatever the package dependency graph is.. But, the packaging algorithm correctly determines that the .NET (Core) framework assembly versions should be set/determined by the project.
Its a bit of a mess - unfortunately it's not a problem specific to Serilog.Sinks.File, just a general NuGet/.NET Core issue. Because this package is low in the dependency graph, and widely used, issue reports for this one often end up here :-)
I've seen one sure-fire workaround suggested - does your project build using the new version of Serilog.Sinks.File if the first package reference in your CSPROJ is the below?:
<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="all" />
Great Nicholas! It works like a charm!
I'm at your disposal for any other test if you need it.
Thank you very much! 😄
Thanks for the follow-up, glad to hear it helped!
Will have to think about how we could make this more discoverable 🤔
At the moment, probably a readme when we install the package and a note on the documentation page are the two places where, from my point of view, I go to search the solution... then Google will do the rest 😉
Thanks for the heads-up!
Serilog.Sinks.File 5.0 now has a
net5.0
target, which I'd hoped would skirt around this issue for that platform, but looks like that might have been unsuccessful :-(. The package previously explicitly referenced the 4.3.x versions of several assemblies to attempt this, but that was in itself problematic and not a long-term fix.The root cause appears to be that at build time, the dependency resolution algorithm (incorrectly?) treats assemblies .NET (Core) framework packages as though they're going to be bundled with the app, and resolves them to a specific version via whatever the package dependency graph is.. But, the packaging algorithm correctly determines that the .NET (Core) framework assembly versions should be set/determined by the project.
Its a bit of a mess - unfortunately it's not a problem specific to Serilog.Sinks.File, just a general NuGet/.NET Core issue. Because this package is low in the dependency graph, and widely used, issue reports for this one often end up here :-)
I've seen one sure-fire workaround suggested - does your project build using the new version of Serilog.Sinks.File if the first package reference in your CSPROJ is the below?:
<PackageReference Include="Microsoft.NETCore.Targets" Version="5.0.0" PrivateAssets="all" />
Could you show an example of the code how to use this line correctly? I can't figure it out in any way, I have low experience in this (
(trimmed a drive by question-comment - @ALEHAAAAANDRO please feel free to re-ask if you can explain what you tried)