Wallace
Wallace

Reputation: 17469

How to correct dotnet restore warning NU1604, does not contain an inclusive lower bound?

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"?

Upvotes: 34

Views: 39316

Answers (6)

Ruben Bartelink
Ruben Bartelink

Reputation: 61885

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.

Upvotes: 3

rish90
rish90

Reputation: 21

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.*" />

Upvotes: 2

silvertiger
silvertiger

Reputation: 85

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.

Upvotes: 1

Heinzlmaen
Heinzlmaen

Reputation: 967

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

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

Upvotes: 5

Monticola Explorator
Monticola Explorator

Reputation: 1318

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.

Upvotes: 17

Carter
Carter

Reputation: 744

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" />

Upvotes: 9

Related Questions