24

While performing a dotnet restore on a .NET Core project (targeting .netcoreapp2.0.), I get the following warning:

warning NU1604: Project dependency System.Net.NameResolution does not contain an inclusive lower bound. Include a lower bound in the dependency version to ensure consistent restore results.

Here is the relevant line from the project file:

<PackageReference Include="System.Net.NameResolution" Verison="4.3.0" />

(If you are wondering, I have included that reference to avoid a warning NU1605: Detected package downgrade.)

How does one "include a lower bound in the dependency version to ensure consistent restore results"?

Wallace Kelly
  • 15,565
  • 8
  • 50
  • 71
  • Related: https://stackoverflow.com/a/43992843/213550 - maybe your project targets lower version of dotnet core/standard, which leads to NuGet warnings – VMAtm Oct 13 '17 at 00:17
  • Maybe useful to others: You can use `dotnet add reference `. It should handle everything for you. – jweyrich May 05 '20 at 19:44

6 Answers6

12

In order to indicate a minimum version for your package references you have to set the Version property of your reference to a range that contains an inclusive lower bound. As @Carter pointed out, Microsoft provides a nice documentation about the format of that property.

If you don't specify an inclusive lower bound for your references, each restore will try to find a lower version of the package that can be used. More information about that warning can be found on the nuget errors and warnings reference page

The only problem with your reference seems to be that you have a typo (Verison instead of Version). So the line should be

<PackageReference Include="System.Net.NameResolution" Version="4.3.0" />

With this line, you indicate that the project requires the version 4.3.0 or above of the package System.Net.NameResolution, hence the inclusive lower bound on 4.3.0.

Monticola Explorator
  • 1,188
  • 13
  • 20
  • 2
    Yea the typo is the key. There must not be a warning about it so make sure you are careful in correctly spelling the attribute names. – Carter Oct 27 '17 at 03:50
  • 1
    Well, Microsoft may provide a nice documentation. The problem is that they don't _link_ to the documentation from the error documentation! Which is why people have to come here. Personally, I thought that Version was _exact_, rather than a lower bound. – Auspex May 07 '19 at 09:32
9

I think the key there is to not include the last digit on your version. Then it will set the lowerbound as 4.3.0 by default.

<PackageReference Include="System.Net.NameResolution" Version="4.3" />
Carter
  • 697
  • 5
  • 22
  • Thanks for the suggestion! I just tried both "4.3" and "4.3.*". The warning is the same. – Wallace Kelly Sep 16 '17 at 14:54
  • That is odd from what I gather on this page that should give it a lower bound. https://learn.microsoft.com/en-us/nuget/reference/package-versioning#version-ranges-and-wildcards Quite a mystery! – Carter Sep 16 '17 at 15:58
  • 1
    @Carter you have a typo in your answer: _Verison_ should read _Version_ , sadly it does not produce any warning on visual studio or msbuild. The original question had the same typo as well, and maybe that was causing the issue. Also, on [link](https://learn.microsoft.com/en-us/nuget/reference/package-versioning#version-ranges-and-wildcards), they say you can use _Patch_ number to indicate minimum version, *"This might be used to guarantee a dependency with a specific bug fix."* – Monticola Explorator Oct 25 '17 at 11:11
  • Interesting. I don't have my test project anymore to know if I was using the misspelling or not. @Wally also misspelled it at least in the question which I am sure is where I copied it from. No idea if it was corrected on projects. – Carter Oct 25 '17 at 15:56
  • @MuscicapaStriata Great catch. I had 'Verison" in my project file. Fixing that caused the warning to go away. If you submit an answer, I'll give you the points. – Wallace Kelly Oct 25 '17 at 21:23
  • Ok. It was fine for me if @Carter just edited his answer, but I will now go ahead and provide my own. – Monticola Explorator Oct 26 '17 at 06:46
  • I tried your suggestion, now I get this error: detected package downgrade: Microsoft.AspNetCore.Authentication.Abstractions from 2.1.1 to 2.1.0. – Brian Feb 05 '19 at 15:44
  • Try cleaning the solution and try to restore again. I've had that issue when intentionally trying to downgrade and if it detects a higher version installed it will reject what's in your dependencies list. – Nick Feb 05 '20 at 14:13
5

Right click "Packages" -> Manage NuGet Packages -> Update

Update all broken packages, if that is not available remove them and add them again.

Heinzlmaen
  • 869
  • 10
  • 20
1

Managing the package version is quite important. you must mention the version or have a floated version specified.

<PackageReference Include="System.Net.NameResolution" Version="4.3" /> or <PackageReference Include="System.Net.NameResolution" Version="4.*" />

rish90
  • 11
  • 3
1

If you are using Central Package Management (and, especially if you are in the middle of switching over manually), check for typos/mangling in your /Directory.Packages.props e.g. the following happened in my case:

<Project>
    ...
    <ItemGroup>
        <PackageVersion Include="MinVer" Version="4.0.0" />

        <!-- EXAMPLE Copy/paste error: Version omitted -->
        <PackageVersion Include="FSharp.Core" />
    </ItemGroup>
</Project>

This lack-of-a-value propagates onto the PackageReference as if you had omitted or mis-spelt the Version attribute name as in the OP.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
0

I got this same error, but it was because I had updated the project from .NET Core 3.1 to .NET 5.0 and the dependencies were incompatible. When I uninstalled and tried to reinstall the packages from the NuGet Package Manager, I got a new warning: Package Microsoft.AspNetCore.Mvc.NewtonsoftJson is not compatible with net5.0. The original error gave no indication this was the case (although in hindsight, the package name did).

TL;DR: Check that your dependencies are compatible with the version of .NET you're using.

silvertiger
  • 55
  • 2
  • 12