Reputation: 18546
Why does my build/restore fail when providing a runtime-identifier win-x64
? Why does it work when I don't? I stumbled across this when trying out self-contained builds.
To put it differently: Why do dotnet restore --runtime win-x64
and dotnet restore
have different dependency graphs?
It works when I use netcoreapp2.1
as a target framework, but it breaks with netcoreapp3.1
or net5.0
. It also works when I remove either of my direct dependencies.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.WebJobs" Version="3.0.23" />
<PackageReference Include="Serilog.Sinks.RollingFileAlternate" Version="2.0.9" />
</ItemGroup>
</Project>
> dotnet restore
Determining projects to restore...
Restored ...\ConsoleApp1\ConsoleApp1.csproj (in 289 ms).
> dotnet restore --runtime win-x64
Determining projects to restore...
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.InteropServices (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.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. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.IO.FileSystem.Primitives (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem.Primitives (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.InteropServices (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Text.Encoding.Extensions from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Console 4.0.0 -> runtime.win.System.Console 4.3.0 -> System.Text.Encoding.Extensions (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Text.Encoding.Extensions (>= 4.0.11) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.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. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.IO.FileSystem.Primitives (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem.Primitives (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.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. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.Handles (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.Handles (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.InteropServices (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Text.Encoding.Extensions from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Text.Encoding.Extensions (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Text.Encoding.Extensions (>= 4.0.11) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: Microsoft.Win32.Primitives from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> Microsoft.Win32.Primitives (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> Microsoft.Win32.Primitives (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Diagnostics.Tracing from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Diagnostics.Tracing (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Diagnostics.Tracing (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.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. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.Handles (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.Handles (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Primitives 4.0.11 -> runtime.win.System.Net.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.InteropServices (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Diagnostics.Tracing from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Diagnostics.Tracing (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Diagnostics.Tracing (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.IO.FileSystem from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.IO.FileSystem (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.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. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.IO.FileSystem.Primitives (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem.Primitives (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Net.Primitives from 4.3.0 to 4.0.11. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Net.Primitives (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Primitives (>= 4.0.11) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.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. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Runtime.Handles (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.Handles (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.InteropServices (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: System.Diagnostics.Tracing from 4.3.0 to 4.1.0. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.IO.FileSystem 4.0.1 -> runtime.win.System.IO.FileSystem 4.3.0 -> System.Buffers 4.3.0 -> System.Diagnostics.Tracing (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Diagnostics.Tracing (>= 4.1.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: Detected package downgrade: Microsoft.Win32.Primitives from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Security.Principal.Windows 4.3.0 -> Microsoft.Win32.Primitives (>= 4.3.0) [...\ConsoleApp1\ConsoleApp1.sln]
...\ConsoleApp1\ConsoleApp1.csproj : error NU1605: ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> Microsoft.Win32.Primitives (>= 4.0.1) [...\ConsoleApp1\ConsoleApp1.sln]
Failed to restore ...\ConsoleApp1\ConsoleApp1.csproj (in 406 ms).
I know I can "fix" it by adding these dependencies, but I would prefer a better solution.
<PackageReference Include="Microsoft.Win32.Primitives" Version="4.3.0" />
<PackageReference Include="System.Net.Primitives" Version="4.3.1" />
<PackageReference Include="System.IO.FileSystem.Primitives" Version="4.3.0" />
<PackageReference Include="System.IO.FileSystem" Version="4.3.0" />
Upvotes: 6
Views: 1308
Reputation: 15213
First, a nit on terminology. netcoreapp2.1
, netcoreapp3.1
and net5.0
are generally called Target Frameworks (and more formally Target Framework Monikers, often abbreviated to TFM). Runtime Identifers (often abbreviated to RID) identify a platform that .NET (Core) is running on top of. They include linux-x64
(Linux on x86_64), win-arm64
(Windows on Arm64) and so on.
A Target Framework identifies the Framework that your application is targeting. A Target Framework includes a number of assemblies (such as System.Collections.Generic
, or System.Runtime.InteropServices
) that it contains. All those assemblies are at specific versions.
Serilog.Sinks.RollingFileAlternate
, as an assembly, also depends on other assemblies. You can see such a few such dependency chains in your output:
ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> Microsoft.Win32.Primitives 4.0.1 -> runtime.win.Microsoft.Win32.Primitives 4.3.0 -> System.Runtime.InteropServices (>= 4.3.0)
ConsoleApp1 -> Serilog.Sinks.RollingFileAlternate 2.0.9 -> NETStandard.Library 1.6.0 -> System.Runtime.InteropServices (>= 4.1.0)
Looking at the second line first, it says Serilog depends on the NETStandard.Library 1.6.0 (equivalent to netstandard1.6
TFM), which depends on a particular version of System.Runtime.InteropServices
, 4.1.0.
The first line says that Serilog depends on Microsoft.Win32.Primitives
, which depends on the runtime package runtime.win.Microsoft.Win32.Primitives
. As I understand it, these runtime.*
packages are provided by your .NET SDK/Runtime installation. So using this leads to a dependency on a newer version of System.Runtime.InteropServices
.
Because two different dependency chains lead to two different versions of `System.Runtime.InteropServices being required, this gets flagged as a downgrade.
If you use netcoreapp2.1
(.NET Core 2.1), that has the runtime.win.Microsoft.Win32.Primitives
package at the lower (and matching) version (4.1.0). In that case, all dependency chains would lead to the same version, and there's no package downgrade identified.
Upvotes: 3