'ERROR: NU1605 "Detected package downgrade" - how to enforce downgrade in .Net5

In the past (and according to current documentation) referencing downgraded nuget package eliminated the above NU1605 (warn/err).

Now, with dotnet SDK 5.0.302, it seems impossible. A sample solution demonstrating it:

  • MyLib reference 1 nuget package : Newtonsoft.Json 13.0.1

My empty solution has this csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net5.0</TargetFramework>       
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
        <PackageReference Include="MyLyb" Version="1.0.0" />
        
    </ItemGroup>
</Project>

Still, I get

error NU1605: Detected package downgrade: Newtonsoft.Json from 13.0.1 to 12.0.3. Reference the package directly from the project to select a different version.

(building from cli, no visual studio involved) I also tried "excludeAssets" with no help.

How can I reference lower version and avoid this error (without hiding it using "NoWarn")



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source